Multiple-thread ROS node crashes on exit when using visualization libraries

asked 2017-05-09 23:11:41 -0500

Bo Li gravatar image

updated 2017-05-09 23:12:29 -0500

Hi, I was trying to integrate a visualization library into a multiple-thread ROS node. The visualization window is created in the main thread to avoid potential issues. However, on my Macbook Pro the node still crashes when given a Ctrl-C exit. The problem happens with both OpenSceneGraph and OpenCV viz module.

Below is a minimal sample:

void loop()
{
    while (true) {}
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "some_node");
    ros::NodeHandle pnh("~"), nh;

    // osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
    // viewer->setUpViewInWindow(0, 0, 640, 480);
    // viewer->frame();

    cv::viz::Viz3d window("win");
    window.spinOnce();
    std::thread thread(loop);

    ros::spin();
}

The first several lines of the crash report:

Process:               ingredient_feeder [26712]
Path:                  /Users/USER/*/ingredient_feeder
Identifier:            ingredient_feeder
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        bash [17709]
Responsible:           ingredient_feeder [26712]
User ID:               501

Date/Time:             2017-05-10 12:08:07.588 +0800
OS Version:            Mac OS X 10.12.4 (16E195)
Report Version:        12
Anonymous UUID:        B9C52243-E85C-1D9E-D9A4-0B6DBE4865F9

Sleep/Wake UUID:       11882BB0-5A55-4BB4-830F-81E4F51A61DD

Time Awake Since Boot: 360000 seconds
Time Since Wake:       4400 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
terminating
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fffe0099d42 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fffe01875bf pthread_kill + 90
2   libsystem_c.dylib               0x00007fffdffff420 abort + 129
3   libc++abi.dylib                 0x00007fffdeb5584a abort_message + 266
4   libc++abi.dylib                 0x00007fffdeb7ab72 default_terminate_handler() + 46
5   libc++abi.dylib                 0x00007fffdeb77d69 std::__terminate(void (*)()) + 8
6   libc++abi.dylib                 0x00007fffdeb77df0 std::terminate() + 64
7   ingredient_feeder               0x000000010248a4dc main + 924
8   libdyld.dylib                   0x00007fffdff6b235 start + 1
edit retag flag offensive close merge delete