ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Node crashes on spinOnce

asked 2014-05-20 08:06:10 -0600

sterlingm gravatar image

Hi, I have a node that is crashing with a

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check

error. The backtrace from gdb says the first call is on a ros::spinOnce() call. The whole stack trace is:

terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check

Program received signal SIGABRT, Aborted.
0x00007ffff6204037 in raise () from /lib/x86_64-linux-gnu/
(gdb) back
#0  0x00007ffff6204037 in raise () from /lib/x86_64-linux-gnu/
#1  0x00007ffff6207698 in abort () from /lib/x86_64-linux-gnu/
#2  0x00007ffff6b11e8d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/
#3  0x00007ffff6b0ff76 in ?? () from /usr/lib/x86_64-linux-gnu/
#4  0x00007ffff6b0ffa3 in std::terminate() () from /usr/lib/x86_64-linux-gnu/
#5  0x00007ffff6b10226 in __cxa_rethrow () from /usr/lib/x86_64-linux-gnu/
#6  0x00007ffff7abf268 in ros::CallbackQueue::callOneCB(ros::CallbackQueue::TLS*) () from /opt/ros/hydro/lib/
#7  0x00007ffff7abeacb in ros::CallbackQueue::callAvailable(ros::WallDuration) () from /opt/ros/hydro/lib/
#8  0x00007ffff7b0579a in ros::spinOnce() () from /opt/ros/hydro/lib/
#9  0x0000000000456892 in Planner::go (this=0x69b8e0 <my_planner>) at /my/code.cpp:962

I was wondering what it means when the code crashes on a spinOnce() call. What should I be looking for? I know there are likely many causes so I am mostly looking for direction rather than a specific answer. My node has three timers and subscribes to 1 topic. All of the callbacks are class methods and access data members in the class that all happen to be std::vectors. But I am not sure if the out_of_range error is one of my class' vectors or something in ROS that gets called in spinOnce().

Basically, all of my callbacks run until the robot reaches the goal. So the main loop looks something like this:

//start timers

while( (latestUpdate_.comparePosition(goal_, false) > goalThreshold_) && ros::ok()) {

// stop timers

I feel like if one of the vectors accessed in a callback was empty, the stack trace would lead me there and not spinOnce. I don't really know what to look for so I can debug. If anyone has suggestions, I would greatly appreciate it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-20 09:51:38 -0600

Your callbacks get serviced when spinOnce() is called, so it is very likely that you access a invalid index of one of your vectors inside a callback. You should compile your package in Debug mode to get a more informative backtrace (if you have not already). If what you posted is already Debug I agree that it should be more informative :)

edit flag offensive delete link more



I was able to track down the bug and it was indeed in my callback functions. I'll accept because it was confirmation that I should keep looking in my callback functions. The stack trace I posted was in Debug mode. It's strange that it didn't lead me to my callback function.

sterlingm gravatar image sterlingm  ( 2014-05-21 10:11:13 -0600 )edit

Question Tools

1 follower


Asked: 2014-05-20 08:06:10 -0600

Seen: 1,163 times

Last updated: May 20 '14