rpng / open_vins

An open source platform for visual-inertial navigation research.
https://docs.openvins.com
GNU General Public License v3.0
2.06k stars 616 forks source link

Segmentation fault / freezing under heavy CPU load #305

Closed pritzvac closed 1 year ago

pritzvac commented 1 year ago

I'm running OpenVINS on ROS1 with stereo data from the RealSense T265 camera. I experienced sporadic crashing / freezing of the VIO under heavy CPU load.

According to GDB, sometimes a segmentation fault happens at https://github.com/rpng/open_vins/blob/98c55256a45b5518cf0a02e0f984cd2afafe99e0/ov_msckf/src/state/State.h#L67 (and sometimes the VIO freezes with one of the threads being in the same location). I assume some elements are deleted from the _clones_IMU map by another thread while iterating over it.

Segmentation fault: Selection_126

Backtrace: Selection_125

I added mutex locks before the for cycle https://github.com/rpng/open_vins/blob/98c55256a45b5518cf0a02e0f984cd2afafe99e0/ov_msckf/src/state/State.h#L67 and before the marginalization and element removal in https://github.com/rpng/open_vins/blob/98c55256a45b5518cf0a02e0f984cd2afafe99e0/ov_msckf/src/state/StateHelper.cpp#L622 where I assume the elements are being deleted from the map. So far it seems to have fixed the issue (I'm testing it by running OpenVINS along with CPU and fileio benchmarks using sysbench). Should I submit a pull request?

goldbattle commented 1 year ago

Yeah, if you are able to. I need to think a bit more about how to elegantly solve this, but I think your fix would solve things.

pritzvac commented 1 year ago

Ok, I made the pull request. I tested it on some rosbag from the euroc dataset running along with the CPU benchmark as well and it seems to fix the issue.