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

Revision history [back]

Do you have any ROS-related variables outside of main? For example, when I write a small node (too small be rolled up inside a class), I usually end up with global variables; main initializes them, and then my callback uses them.

But: global variables get constructed before main is called, so if you're using something that refers to a NodeHandle internally, you'll get this error. I almost always get it with tf::TransformListener, just because I forget that it's going to happen.

The solution is to store a pointer (I generally use a boost::shared_ptr<T>) to that object, not just a raw object, and then fill the pointer in in main after you call ros::init().