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

Revision history [back]

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.

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.