[SOLVED] (workaround) cfclient segmentation fault

Post here to get support
Post Reply
Fr4nky
Beginner
Posts: 13
Joined: Tue May 13, 2014 7:00 pm
Location: Vienna

[SOLVED] (workaround) cfclient segmentation fault

Post by Fr4nky » Mon Sep 28, 2015 7:46 pm

Hello,

I have upgraded to the newest version of the client (develop branch) on Ubuntu 14.04 and installed all the Python3 dependencies.
The client window opens, however after about half a second it closes again (with the button to the right of the Connect button still showing "Scanning..."), giving me a segmentation fault error.
The cause of the error seems to be line 72 in crazyflie-clients-python/lib/cflib/drivers/cfusb.py in the function _find_devices()
I added some debug prints to the function so now it looks like this:

Code: Select all

def _find_devices():
    """
    Returns a list of CrazyRadio devices currently connected to the computer
    """
    ret = []

    logger.info("Looking for devices....")

    if pyusb1:
        logger.info("pyusb1")
        for d in usb.core.find(idVendor=USB_VID, idProduct=USB_PID, find_all=1,  #segmentation fault here
                               backend=pyusb_backend):
            ret.append(d)
    else:
        logger.info("not pyusb1")
        busses = usb.busses()
        for bus in busses:
            for device in bus.devices:
                if device.idVendor == USB_VID:
                    if device.idProduct == USB_PID:
                        ret += [device, ]
    logger.info("Looking for devices done")
    return ret
This is the error i am getting:

Code: Select all

...
WARNING:cfclient.ui.tabs.GpsTab:GPS tab not enabled since no Pythonbindings for Marble was found
INFO:cflib.crtp.radiodriver:v0.52 dongle with serial N/A found
INFO:cflib.drivers.cfusb:Looking for devices....
INFO:cflib.drivers.cfusb:pyusb1
Segmentation fault
So it seems to me like calling usb.core.find() is causing the problems. However, I tested it in the Bitcraze VM with the same pyusb version and it works fine.
Does anyone have an idea how to fix this?

Thanks and Regards,
Daniel
Last edited by Fr4nky on Fri Oct 16, 2015 12:32 pm, edited 2 times in total.



marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: cfclient segmentation fault

Post by marcus » Tue Oct 13, 2015 10:04 am

Hi,

There's two things that comes to mind:
  • Mixing 32bit and 64bit libraries: Check that you consistently have the same version (i.e if Python3 is 32bit then the dependencies should be as well)
  • Issue with libusb/pyusb: There's a few different versions of these and the API changes between them. What versions of pyusb and libusb are you using?
To get some more information about the crash you can try running the client with gdb (it might need to be installed). Once you hit the segfault it should stop and typing bt should give you a strack-trace (although not in Python).

If you're not interested in using the Crazyflie with USB a workaround is to remove the UsbDriver class from this line

BR,
Marcus

Fr4nky
Beginner
Posts: 13
Joined: Tue May 13, 2014 7:00 pm
Location: Vienna

Re: cfclient segmentation fault

Post by Fr4nky » Tue Oct 13, 2015 6:44 pm

Hello,

Thanks for the suggestions!
Python3 and the necessary libraries are 64bit. libusb is version 1.0.17 and python3-usb is version 1.0.0.
gdb gives me the following output:

Code: Select all

...
INFO:cflib.drivers.cfusb:Looking for devices....
[New Thread 0x7fffbbfff700 (LWP 1348)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff977fe700 (LWP 1327)]
libusb_get_bus_number (dev=0xffffffff880558b0) at core.c:660
660	core.c: No such file or directory
and then the bt-command:

Code: Select all

#0  libusb_get_bus_number (dev=0xffffffff880558b0) at core.c:660
#1  0x00007ffff1afeadc in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#2  0x00007ffff1afe40c in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#3  0x00007fffe310613d in _ctypes_callproc () from /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so
#4  0x00007fffe31066b3 in ?? () from /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so
#5  0x00000000004b2627 in PyEval_EvalFrameEx ()
#6  0x00000000004b234d in PyEval_EvalFrameEx ()
#7  0x000000000056a7ec in ?? ()
#8  0x00000000004e21bd in ?? ()
...
So it seems like libusb_get_bus_number is causing the problem.
The workaround works great, and since I will not be using the USB connection I'll go with it.

Thanks and Regards,
Daniel

marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: cfclient segmentation fault [SOLVED (workaround)]

Post by marcus » Tue Oct 13, 2015 7:10 pm

Thanks for the info. It's strange that the Crazyradio works though. As far as I can see the code for finding the device is the same.

Could you try starting the client with and without the Crazyradio? Just to check if there's an issue when the device isn't found.

Fr4nky
Beginner
Posts: 13
Joined: Tue May 13, 2014 7:00 pm
Location: Vienna

Re: cfclient segmentation fault [SOLVED (workaround)]

Post by Fr4nky » Tue Oct 13, 2015 7:20 pm

I haven't actually tried it with a CR yet since I don't have one here right now. I will try tomorrow and keep you posted.

Fr4nky
Beginner
Posts: 13
Joined: Tue May 13, 2014 7:00 pm
Location: Vienna

Re: cfclient segmentation fault [SOLVED (workaround)]

Post by Fr4nky » Wed Oct 14, 2015 7:39 pm

Hello,

I now tested a few things with the Crazyradio.
Without the workaround the client crashes as described in the first post with and without the Crazyradio plugged in.
With the workaround the client finds the dongle and it can connect to the CFN just fine.
However when trying to scan, it crashes with a segfault:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff977fe700 (LWP 29291)]
libusb_get_bus_number (dev=0xffffffff8801ee40) at core.c:660
660	core.c: No such file or directory
(gdb) bt
#0  libusb_get_bus_number (dev=0xffffffff8801ee40) at core.c:660
#1  0x00007ffff1afeadc in ffi_call_unix64 ()
   from /usr/lib/x86_64-linux-gnu/libffi.so.6
#2  0x00007ffff1afe40c in ffi_call ()
   from /usr/lib/x86_64-linux-gnu/libffi.so.6
Cannot access memory at address 0x7fff977fc4a8
Regards,
Daniel

marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: [SOLVED] (workaround) cfclient segmentation fault

Post by marcus » Tue Oct 20, 2015 9:20 am

Thanks for the extra information! It would be great if you wanted to summarize it in an issue on GitHub and we will look into it.

Fr4nky
Beginner
Posts: 13
Joined: Tue May 13, 2014 7:00 pm
Location: Vienna

Re: [SOLVED] (workaround) cfclient segmentation fault

Post by Fr4nky » Tue Oct 20, 2015 11:09 am


marcus
Bitcraze
Posts: 599
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: [SOLVED] (workaround) cfclient segmentation fault

Post by marcus » Tue Oct 20, 2015 11:35 am

Thanks!

Post Reply