I'm currently making a robot using Phidgets and an onboard Intel Nuc and ROS.
I'm running into a really weird segfault issue that's originating from (after hours of testing/bugfinding/rewriting code) libusb. I finally stumbled upon CPhidget_enableLogging(PHIDGET_LOG_INFO, NULL);
That enabled me to see the libusb errors that happen non-deterministically, and (sometimes) cause my program to segfault.
This is an example where the program would segfault.
Code: Select all
int error = CPhidgetMotorControl_create(&(motors[i].control));
if(error != EPHIDGET_OK)
{
ROS_ERROR_STREAM("Phidget error: " << error << " when creating motor controller.");
}
CPhidget_set_OnAttach_Handler((CPhidgetHandle) motors[i].control, AttachHandler, NULL);
CPhidget_enableLogging(PHIDGET_LOG_INFO, NULL);
error = CPhidget_open((CPhidgetHandle) motors[i].control, motors[i].serial);
if(error != EPHIDGET_OK)
{
ROS_ERROR_STREAM("Phidget error: " << error << " when opening motor controller.");
}
int result;
// Wait up to 10000 ms for a device to be plugged in
if((result = CPhidget_waitForAttachment((CPhidgetHandle) motors[i].control, 10000))){
ROS_ERROR_STREAM("Phidget error: " << error << " when attempting to open motor controller.");
}
ROS_INFO("Got Here: %i", motors[i].serial);
Log:
INFO: Enabling logging
INFO: Initializing libusb
INFO: New device in CUSBBuildList: 2/16
INFO: New device in CUSBBuildList: 2/15
INFO: New device in CUSBBuildList: 2/14
ERR: Unexpected error converting string to UTF-8: Invalid argument.
INFO: New device in CUSBBuildList: 2/13
INFO: New device in CUSBBuildList: 2/12
INFO: New device in CUSBBuildList: 2/10
ERR: Unexpected error converting string to UTF-8: Invalid argument.
INFO: New device in CUSBBuildList: 2/9
INFO: New device in CUSBBuildList: 2/8
INFO: New device in CUSBBuildList: 2/7
INFO: New device in CUSBBuildList: 2/6
INFO: New device in CUSBBuildList: 2/5
INFO: Using Control Endpoint for Host->Device communication.
INFO: WriteThread running
[ INFO] [1462074018.351383333]: New Device Attached
INFO: ReadThread running
[ INFO] [1462074018.360556966]: Got Here: 395285
INFO: Enabling logging
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
WARN: unable to open active device: 1
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
*** Error in `/home/urmp/robotic-mining/urmpspace/devel/lib/astro/simple_drive': double free or corruption (top): 0x00000000011b95d0 ***
Aborted (core dumped)
Like I said above, this happens sometimes at startup (I'm assuming when calling CPhidget_open); and when it doesn't happen the program will run forever without a crash; another strange thing is that it happens only when I'm using my Intel Nuc to program. If I use any other laptops running the same OS, or virtualized in Parallels this doesn't happen.
There are also a couple other types of errors, shown below; and also, occasionally an error will be shown, but the program doesn't segfault.
Any help would be extremely appreciated. The NASA competition this robot is going to starts in two weeks!
Other Error Logs:
1 (No Segfault, and works after this point):
INFO: Enabling logging
[ERROR] [1462074455.255049030]: Phidget error: 12 when opening motor controller.
WARN: Failure in CUSBReadPacket - Report Length: 0, bytes read: 25. Probably trying to use too many Phidgets at once, and some data is being lost.
INFO: ReadThread exiting normally (Phidget detached)
INFO: WriteThread exiting normally (Phidget detached)
INFO: Using Control Endpoint for Host->Device communication.
INFO: WriteThread running
2 (Segfaulted):
urmp@urmp-robot:~/robotic-mining/urmpspace/src/astro$ rosrun astro simple_drive INFO: Enabling logging
INFO: Initializing libusb
INFO: New device in CUSBBuildList: 2/16
INFO: New device in CUSBBuildList: 2/15
INFO: New device in CUSBBuildList: 2/14
INFO: New device in CUSBBuildList: 2/13
ERR: Unexpected error converting string to UTF-8: Invalid argument.
INFO: New device in CUSBBuildList: 2/12
INFO: New device in CUSBBuildList: 2/10
INFO: New device in CUSBBuildList: 2/9
INFO: New device in CUSBBuildList: 2/8
INFO: New device in CUSBBuildList: 2/7
INFO: New device in CUSBBuildList: 2/6
INFO: New device in CUSBBuildList: 2/5
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
INFO: Using Control Endpoint for Host->Device communication.
ERR: Unexpected error converting string to UTF-8: Invalid argument.
ERR: CUSBGetDeviceCapabilities returned nonzero code: 3
INFO: WriteThread running
[ INFO] [1462074504.815540327]: New Device Attached
Segmentation fault (core dumped)
3: Segfault
INFO: Enabling logging
INFO: Initializing libusb
INFO: New device in CUSBBuildList: 2/16
INFO: New device in CUSBBuildList: 2/15
INFO: New device in CUSBBuildList: 2/14
INFO: New device in CUSBBuildList: 2/13
INFO: New device in CUSBBuildList: 2/12
INFO: New device in CUSBBuildList: 2/10
INFO: New device in CUSBBuildList: 2/9
INFO: New device in CUSBBuildList: 2/8
INFO: New device in CUSBBuildList: 2/7
INFO: New device in CUSBBuildList: 2/6
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
ERR: libusb_get_string_descriptor_ascii failed with error code: -1
*** Error in `/home/urmp/robotic-mining/urmpspace/devel/lib/astro/simple_drive': double free or corruption (!prev): 0x0000000000845840 ***
Aborted (core dumped)
Another note: If you need me to launch it in GDB I can give you the backtrace... But it happens in a different thread so I can't get the original line in my code that it happened. Just let me know!