gaoxiang12 / slambook2

edition 2 of the slambook
MIT License
5.3k stars 1.99k forks source link

fix issue in backend::optimise with map::at() #289

Closed rebmaso closed 9 months ago

rebmaso commented 9 months ago

First, thanks for the great work to @gaoxiang12 and all the maintainers.

Found an issue in the backend loop:

If somehow execution is slowed down, std::map::at() throws out of range exception as it is looking for an element in vertices that has not been added yet.

The faulty line is: edge->setVertex(0, vertices.at(frame->keyframe_id_));

This happens because if enough time has passed from when the vertices are assigned with the value from the map, a landmark might be observed by a keyframe that has not been inserted yet in the pose vertices.

To be sure, I added a check on the landmark vertices as well, even if the problem presents itself because of pose vertices.

Steps to replicate: just add some LOG(INFO) 's right before edge->setId(index); to slow down execution intentionally and error should pop up.

gaoxiang12 commented 9 months ago

Thanks for PR!