ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It looks like you might misunderstand the way smart pointers work. You can look hear for an intro: http://www.boost.org/doc/libs/1_46_1/libs/smart_ptr/smart_ptr.htm
But in the mean time smart pointers can only be safely used to represent heap allocations (things created with new
) If you try to get image_msg
from your example into a smart pointer rosimg
it will cause a segfault because it will be deleted twice: Once from going out of scope, and second by the smart pointer when ever it goes out of scope or is otherwise destroyed.
Write your call back to use const sensor_msgs::Image::Ptr & image_msg
and ros will pass you the message wrapped in a smart pointer already, and you won't have to worry about it.
2 | No.2 Revision |
It looks like you might misunderstand the way smart pointers work. You can look hear for an intro: http://www.boost.org/doc/libs/1_46_1/libs/smart_ptr/smart_ptr.htm
But in the mean time smart pointers can only be safely used to represent heap allocations (things created with new
) If you try to get image_msg
from your example into a smart pointer rosimg
it will cause a segfault because it will be deleted twice: Once from going out of scope, and second by the smart pointer when ever it goes out of scope or is otherwise destroyed.
Write If you write your call back message callback to use const sensor_msgs::Image::Ptr & image_msg
and , ros will pass you the message wrapped in a smart pointer already, already , and you won't have to worry about it.