raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.34k stars 4.69k forks source link

Shutdown problem in System.cc #547

Open kjwkch opened 6 years ago

kjwkch commented 6 years ago

Hi.

I found shutdown fuction problem. I think that mpViewer is not cleared. So, program is killed by pangolin::BindToContext("ORB-SLAM2: Map Viewer") line on windows. I added codes that clear mpViewer and have used.

`void System::Shutdown()

{

mpLocalMapper->RequestFinish();

mpLoopCloser->RequestFinish();

if(mpViewer)

{

    mpViewer->RequestFinish();

    while(!mpViewer->isFinished())

        usleep(5000);
    /* add code
    delete mpViewer;
    mpViewer = static_cast<Viewer*>(NULL);
    */
}

// Wait until all thread have effectively stopped

while(!mpLocalMapper->isFinished() || !mpLoopCloser->isFinished() || mpLoopCloser->isRunningGBA())

{

    usleep(5000);

}

if(mpViewer)  // <- always 'true'

    pangolin::BindToContext("ORB-SLAM2: Map Viewer");

}`

BoomFan commented 6 years ago

Thanks! I was running into a shutdown problem and I tried your code. It works! But somehow, after the trajectory is saved, I got errors like this:

QObject::~QObject: Timers cannot be stopped from another thread
Segmentation fault (core dumped)

Do you have the same issue?

kjwkch commented 6 years ago

No. I think that the issue is occurred saving trajectory before ORB_SLAM2.Shutdown(). Call Shutdown first.

Below the code is 'System.h' `// All threads will be requested to finish. // It waits until all threads have finished. // This function must be called before saving the trajectory. void Shutdown();

// Save camera trajectory in the TUM RGB-D dataset format.
// Only for stereo and RGB-D. This method does not work for monocular.
// Call first Shutdown()
// See format details at: http://vision.in.tum.de/data/datasets/rgbd-dataset
void SaveTrajectoryTUM(const string &filename);

// Save keyframe poses in the TUM RGB-D dataset format.
// This method works for all sensor input.
// Call first Shutdown()
// See format details at: http://vision.in.tum.de/data/datasets/rgbd-dataset
void SaveKeyFrameTrajectoryTUM(const string &filename);

// Save camera trajectory in the KITTI dataset format.
// Only for stereo and RGB-D. This method does not work for monocular.
// Call first Shutdown()
// See format details at: http://www.cvlibs.net/datasets/kitti/eval_odometry.php
void SaveTrajectoryKITTI(const string &filename);`
BoomFan commented 6 years ago

Here is my mono_kitti.cc file. It seems like SaveKeyFrameTrajectoryTUM() is at the very end of this code, right? image

But I still got this error: image

Do you think we have to add more to void System::Shutdown() function?

PengshuaiChai commented 6 years ago

I followed your suggestion and it worked.Then ,I have the same question with BoomFan . 2018-03-28 14-42-03

dyz-zju commented 6 years ago

QObject::~QObject: Timers cannot be stopped from another thread Segmentation fault (core dumped)

I met same error as you after followed your suggestion. Do you find the solution? @kjwkch @BoomFan @PengshuaiChai

dyz-zju commented 6 years ago

I have solved the problem which is related to Pangolin branch, we need not to change the source code and just need to use a older branch of pangolin.

georgebola commented 6 years ago

Can you provide us with the branch of pangolin that worked for you ( link if possible) ?

dyz-zju commented 6 years ago

you can provide me a email, I will send to you.@georgebola

ryanismert commented 6 years ago

I had success just commenting out the call to BindToContext(). Save trajectory was called fine, and no segfault.

joebedard commented 6 years ago

I debugged BindToContext() and it looks like there is a mutex deadlock in Pangolin. The workaround suggested by @kjwkch also works for me. I think it is a better approach because (deleting mpViewer) should detach the viewer thread from the (OpenGL) context (see Pangolin Issue 111 comment from stevenlovegrove). I suspect this is the intention of the the call to BindToContext().

amitfishy commented 6 years ago

I'm using stereo_kitti.cc and what @kjwkch suggested works for me. I get the following output:

median tracking time: 0.108392
mean tracking time: 0.111087

Saving camera trajectory to CameraTrajectory.txt ...

trajectory saved!
Exiting...           //cout<<"Exiting...\n"; just before return 0;
QObject::~QObject: Timers cannot be stopped from another thread

No segmentation fault occurs but it still gives the message QObject::~QObject: Timers cannot be stopped from another thread while exiting. Not sure if this will mess with anything if I have code running after saving the map. The entries in the CameraTrajectory.txt seem to be fine though.

caolk commented 6 years ago

Thanks! I solve this problem according to your suggestion. @dyz-zju I found an old version of Pangolin at https://github.com/stevenlovegrove/Pangolin/tree/8b8b7b96adcf58ac2755dedd3f681fc512385af0 It works quite well.

ap108 commented 6 years ago

Hi, I tried the code edits to the present version of Pangolin, and the older version of Pangolin but I also get

QObject::~QObject: Timers cannot be stopped from another thread
Segmentation fault (core dumped)

@kjwkch @BoomFan @PengshuaiChai Is there a solution?

Is it OK to use ORB-SLAM with these errors on shutdown ? I still get the trajectory file.

Thanks

kerolex commented 6 years ago

Thanks @kjwkch.

I compiled Pangolin from the master branch on the 9th of August and your solution works perfectly fine on my side with all files, e.g. trajectories, saved.