From bade1ec4c6cc2cb9cd87459459fbd5c0f7b1e24d Mon Sep 17 00:00:00 2001 From: Automatic Release Builder <build@flightgear.org> Date: Sun, 23 Aug 2020 17:41:09 +0100 Subject: [PATCH] Attempt to fix ref-ptr crash on exit Fixing Sentry issue FLIGHTGEAR-9 --- src/Main/globals.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index a54515971..16a4812dc 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -207,14 +207,19 @@ FGGlobals::~FGGlobals() // 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) { - // 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(); + // there are some scenarios where renderer is already gone. + osg::ref_ptr<osgViewer::Viewer> vw; + if (renderer) { + 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(); + } } + subsystem_mgr->shutdown(); subsystem_mgr->unbind(); @@ -229,14 +234,14 @@ FGGlobals::~FGGlobals() subsystem_mgr->remove(FGScenery::staticSubsystemClassId()); // renderer touches subsystems during its destruction - set_renderer(NULL); + set_renderer(nullptr); FGFontCache::shutdown(); fgCancelSnapShot(); delete subsystem_mgr; - subsystem_mgr = NULL; // important so ::get_subsystem returns NULL - vw = nullptr; // don't delete the viewer until now + subsystem_mgr = nullptr; // important so ::get_subsystem returns NULL + vw = nullptr; set_matlib(NULL); delete time_params;