]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/globals.cxx
AI subsystem now does an orderly shutdown
[flightgear.git] / src / Main / globals.cxx
index f2c57e15d2ece5345a1b7002f1a80d9a4786bf38..de3124dc418eee55881176d3c516339a25a0990e 100644 (file)
@@ -199,26 +199,8 @@ FGGlobals::~FGGlobals()
     // save user settings (unless already saved)
     saveUserSettings();
 
-    // 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
-    // deallocation of AIModel objects. To ensure we can safely
-    // shut down all subsystems, make sure we take down the
-    // AIModels system first.
-    SGSubsystemRef ai = subsystem_mgr->get_subsystem("ai-model");
-    if (ai) {
-        subsystem_mgr->remove("ai-model");
-        ai->unbind();
-        ai.clear(); // ensure AI is deleted now, not at end of this method
-    }
-
-    subsystem_mgr->shutdown();
-    subsystem_mgr->unbind();
-
-    subsystem_mgr->remove("aircraft-model");
-    subsystem_mgr->remove("model-manager");
-
-    subsystem_mgr->remove(FGTileMgr::subsystemName());
+    // stop OSG threading first, to avoid thread races while we tear down
+    // scene-graph pieces
 
     osg::ref_ptr<osgViewer::Viewer> vw(renderer->getViewer());
     if (vw) {
@@ -229,6 +211,10 @@ FGGlobals::~FGGlobals()
         vw->stopThreading();
     }
 
+    subsystem_mgr->shutdown();
+    subsystem_mgr->unbind();
+
+    subsystem_mgr->remove(FGTileMgr::subsystemName());
     // don't cancel the pager until after shutdown, since AIModels (and
     // potentially others) can queue delete requests on the pager.
     if (vw && vw->getDatabasePager()) {