ros-perception / laser_filters

Assorted filters designed to operate on 2D planar laser scanners, which use the sensor_msgs/LaserScan type.
BSD 3-Clause "New" or "Revised" License
175 stars 206 forks source link

Don't use shared_from_this in the constructor #197

Closed bjsowa closed 4 months ago

bjsowa commented 4 months ago

Using shared_from_this inside a constructor is dangerous:

If shared_from_this is called on an object that is not previously shared by std::shared_ptr, std::bad_weak_ptr is thrown (by the shared_ptr constructor from a default-constructed weak-this).

Right now, running scan_to_cloud_filter_chain results in std::bad_weak_ptr exception.

This PR fixes it by using a different constructor for tf2_ros::MessageFilter

bjsowa commented 4 months ago

LGTM. Thanks for fixing this bug!! Can really tell people haven't been using that node and that our test coverage needs improvement :-/

This bug was introduced by #188 so I caught it just a day after. I agree that tests should have detected it though.