SteveMacenski / slam_toolbox

Slam Toolbox for lifelong mapping and localization in potentially massive maps with ROS
GNU Lesser General Public License v2.1
1.68k stars 525 forks source link

Fix segfault after loading posegraph #527

Closed samiamlabs closed 2 years ago

samiamlabs commented 2 years ago

Basic Info

I was getting a segfault in in localization_slam_toolbox_node after loading a posegraph from a file here in the code: https://github.com/SteveMacenski/slam_toolbox/blob/ae68b851094668738fd32e8dc6e72e18fd15a965/src/loop_closure_assistant.cpp#L189

The problem is that the LoopClosureAssistant was created with a raw pointer to a karto::Mapper instance from a unique pointer. The raw pointer is not replaced when a new serialized pose graph is loaded. Trying to call functions on the mapper_ pointer in the LoopClosureAssistant after that will cause a segfault.

| Primary OS tested on | Ubuntu | | Robotic platform tested on | gazebo simulation of Husky |


Description of contribution in a few bullet points

Future work that may be required

It seems a bit strange to me that LoopClosureAssistant is using raw pointers rather that smart pointers. I suspect there is a reason for this thought... If not, it not we should probably change it so it uses smart pointers and avoid segfaults like this.

SteveMacenski commented 2 years ago

It seems a bit strange to me that LoopClosureAssistant is using raw pointers rather that smart pointers. I suspect there is a reason for this thought...

At the time of writing, I had just gotten out of several months working in the core of lib KartoSDK which has raw pointers galore for the graph-SLAM representations so it was just the headspace I was in. Plus,