ivipsourcecode / DS-SLAM

GNU General Public License v3.0
678 stars 140 forks source link

Bug in pointcloudmapping.cc PointCloudMapping::viewer() #38

Open MelancholyMethane opened 2 years ago

MelancholyMethane commented 2 years ago

A lock should be added when calling generatePointCloud, or the addresses of the vectors may shift when other threads execute the push_back operation. This is especially likely to happen in a device where the memory is limited and the memory block allocated initially is not large enough. If it happens, a segmentation fault will result. Wrong:

        for ( size_t i=lastKeyframeSize; i<N ; i++ )
        {
            PointCloud::Ptr p = generatePointCloud( keyframes[i],semanticImgs_color[i], semanticImgs[i],colorImgs[i], depthImgs[i] );
            *KfMap += *p;
            *globalMap += *p;       
        }

A possible correction:

        for ( size_t i=lastKeyframeSize; i<N ; i++ )
        {
            unique_lock<mutex> lck(keyframeMutex);
            PointCloud::Ptr p = generatePointCloud( keyframes[i],semanticImgs_color[i], semanticImgs[i],colorImgs[i], depthImgs[i] );
            *KfMap += *p;
            *globalMap += *p;       
        }