Segmentation Fault in LocalMapping for stereo_inertial
Hi,
I am trying to run ORB-SLAM3 (ROS version) with T265. My colleagues recorded a ROS bag including stereo images and imu topics. When we run ORB-SLAM3 in slam mode, there is always a chance that a segmentation fault occurs. We used gdb to debug this issue and found the problem may lie in LocalMapping thread (in function CreateNewMapPoints or KeyFrameCulling) since every time the error info will be something like the following:
Thread 6 "Stereo_Inertial" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffcbc63700 (LWP 5098)]
0x00007ffff7d02e35 in ORB_SLAM3::LocalMapping::CreateNewMapPoints (this=0x555555ac8160)
at /usr/include/c++/9/bits/stl_vector.h:1058
1058 operator[](size_type __n) const _GLIBCXX_NOEXCEPT
Thread 6 "Stereo_Inertial" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffcbc63700 (LWP 95196)]
0x00007ffff7d0510f in ORB_SLAM3::LocalMapping::KeyFrameCulling (this=0x555555ac8160)
at /usr/include/c++/9/bits/stl_vector.h:1058
1058 operator[](size_type __n) const _GLIBCXX_NOEXCEPT
We suspect that the index of some vectors in these two functions is out of bounds. Currently we commented the KeyFrameCulling() function and focus on solving the issue in CreateNewMapPoints(). We inserted cout before and after the following line:
if (i > 0 && CheckNewKeyFrames())
and found this might be the reason causing this segmentation fault. However, we failed to find a solution to further debug this issue. Could anyone be so kind to provide any insight to solve this problem? Many thanks.
Any help or discussion is appreciated.
The reason seems to be within Frame.cc... When using a stereo fisheye camera, the vector mvDepth and mvuRight are declared as follows:
mvDepth = vector<float>(Nleft,-1.0f);
mvuRight = vector<float>(Nleft,-1);
However, their values are assigned later by the index iL
mvDepth[iL]=mbf/disparity;
mvuRight[iL] = bestuR;
where iL ranges from 0 to N-1. Therefore in LocalMapping.cc, the definition of kp1_ur and kp2_ur:
const float kp1_ur=mpCurrentKeyFrame->mvuRight[idx1];
...
const float kp2_ur = pKF2->mvuRight[idx2];
if you use a if statement to find the relationship between idx1/idx2 and mvuRight.size(), you will notice in many cases the index will exceed the length of the vector.
For now I simply modified the length of the vectors from Nleft to N and the segmentation fault seems to be solved. However, the quality of the created map is somehow affected. Need time for further investigation.