yookyung1310 / labstreaminglayer

Automatically exported from code.google.com/p/labstreaminglayer
0 stars 0 forks source link

pylsl.py segfaults in OSX #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. cd labstreaminglayer/LSL/liblsl-Python/examples/
2. python SendData.py
or, alternatively
2. python SendDataAdvanced.py

What do you see instead?
Segmentation fault: 11

These examples work fine for us in Linux.

What version of the product are you using? On what operating system?
lsl 1.10; Python 2.7.8 installed view homebrew on OSX 10.10.1 Yosemite

Please provide any additional information below.
Stepping through the code, I see it fails in pylsl.py line 333:
self.obj = lib.lsl_create_outlet(info.obj,chunk_size,max_buffered)

I tried changing chunk_size and max_buffered to non default values but still 
segfaulted.

In SendDataAdvanced.py, it fails in the call to pylsl.py line 288:
lib.lsl_get_desc(self.obj)

The handle to info.obj appears to be OK (e.g., 140365924480576)

Original issue reported on code.google.com by chadwick...@gmail.com on 11 Dec 2014 at 4:09

GoogleCodeExporter commented 8 years ago
Maybe this is relevant:
http://stackoverflow.com/questions/12482364/ctypes-class-member-access-segfaulti
ng

That would explain why lib.lsl_create_streaminfo works (its arguments are 
wrapped in ctypes) but none of the other calls to lib do.

Original comment by chadwick...@gmail.com on 3 Mar 2015 at 4:06

GoogleCodeExporter commented 8 years ago
That did indeed fix it, at least partially. I can now SendData but I cannot 
ReceiveData because I do not know how to specify dynamically sized buffers. If 
I set the argtypes for the lib.lsl_pull_sample_f function then I get this error:

ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected 
LP_c_float instance instead of pointer to c_float_Array_8

It might be necessary to cast the buffer to the correct pointer type when the 
function is called.
See:
http://stackoverflow.com/questions/8392203/dynamic-arrays-and-structures-in-stru
ctures-in-python

Original comment by chadwick...@gmail.com on 3 Mar 2015 at 7:04

GoogleCodeExporter commented 8 years ago
It seems the file didn't get attached. Trying again. Here is the diff on 
pylsl.py

Original comment by chadwick...@gmail.com on 3 Mar 2015 at 7:04

Attachments:

GoogleCodeExporter commented 8 years ago
I ended up casting the pointer/buffer when the buffer was created. I also had 
to make a change to how pull_sample was reading the data. Now SendData, 
ReceiveData, and ReceiveDataInChunks all work. Please take a look at the 
changes to see if there is any expectation they will kill performance.

Cheers,
Chad

Original comment by chadwick...@gmail.com on 3 Mar 2015 at 7:59

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks Chad for this excellent fix! Unfortunately, the fix on OSX seems to 
break pylsl on Windows and Linux. I am currently in the process of finding the 
exact source of the issue. Once this is resolved, I will incorporate these 
changes into the current trunk. 

Thank you, again. This is awesome -- RecorderLib64.dylib too.

Original comment by david.er...@gmail.com on 4 Mar 2015 at 6:12

GoogleCodeExporter commented 8 years ago
OK. So I have made one revision to Chad's version of pylsl.py. It seems that a 
couple of lines got deleted from the original version and this change didn't 
make into the change log for some reason. These are lines 305-307:
    def handle(self):
        """Get the implementation handle."""
        return self.obj

This should work in Windows and Linux with no problems. The test programs in 
the LSL/liblsl-Python/examples folder all work perfectly on OSX, but I am still 
getting a segfault when I run LabRecorder.py. This occurs when I stop recording 
-- so this needs a little bit more investigation.

Original comment by david.er...@gmail.com on 4 Mar 2015 at 8:29

Attachments:

GoogleCodeExporter commented 8 years ago
I don't think I deleted those lines. Anyway, thanks for finding that.

I also have the segfault when stopping recording. My guess is that it is a 
similar cause (argtypes) but in RecorderLib. Because it is in RecorderLib I 
considered it to be a separate issue to this one.

Original comment by chadwick...@gmail.com on 4 Mar 2015 at 8:44

GoogleCodeExporter commented 8 years ago
Yeah, who knows how that happened. In any case, it was causing all kinds of 
mischief. I am inclined to close this issue, but I wonder if the seg-faulting 
in OSX can be stemmed with further revision to pylsl.py rather than 
LabRecorder.py. Honestly, I am not (yet) expert enough on python to make that 
judgment. Christian may be able to give a better idea about this. TBC...

Anyways, thanks again, Chad.

Original comment by david.er...@gmail.com on 4 Mar 2015 at 9:05