From b7c88e7acc8e0197de11c9095d88fbfc5d03f0a5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 18 Dec 2015 22:00:37 -0800 Subject: [PATCH] Stop OSG threading earlier on shutdown. Avoid intermittent race conditions on shutdown when the OSG pager/Db thread is running. Ensure the OSG threads are stopped before we start tearing down any scene graph nodes. --- src/Main/globals.cxx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index e3f7cbcf3..084d77128 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -199,6 +199,19 @@ FGGlobals::~FGGlobals() // save user settings (unless already saved) saveUserSettings(); + // stop OSG threading first, to avoid thread races while we tear down + // scene-graph pieces + + osg::ref_ptr vw(renderer->getViewer()); + if (vw) { + // https://code.google.com/p/flightgear-bugs/issues/detail?id=1291 + // explicitly stop trheading before we delete the renderer or + // viewMgr (which ultimately holds refs to the CameraGroup, and + // GraphicsContext) + vw->stopThreading(); + } + +#if 0 // The AIModels manager performs a number of actions upon // Shutdown that implicitly assume that other subsystems // are still operational (Due to the dynamic allocation and @@ -211,21 +224,12 @@ FGGlobals::~FGGlobals() ai->unbind(); ai.clear(); // ensure AI is deleted now, not at end of this method } +#endif subsystem_mgr->shutdown(); subsystem_mgr->unbind(); subsystem_mgr->remove(FGTileMgr::subsystemName()); - - osg::ref_ptr vw(renderer->getViewer()); - if (vw) { - // https://code.google.com/p/flightgear-bugs/issues/detail?id=1291 - // explicitly stop trheading before we delete the renderer or - // viewMgr (which ultimately holds refs to the CameraGroup, and - // GraphicsContext) - vw->stopThreading(); - } - // don't cancel the pager until after shutdown, since AIModels (and // potentially others) can queue delete requests on the pager. if (vw && vw->getDatabasePager()) { -- 2.39.5