From af40bcb60e4babb60c54fabb06545819d9273027 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 12 Nov 2013 22:26:37 +0000 Subject: [PATCH] Reset: explicit close-window function. Allow orderly shutdown of OSG before cxa_finalize --- src/Main/fg_os.hxx | 1 + src/Main/main.cxx | 1 + src/Scenery/scenery.cxx | 10 +++++++++- src/Scenery/scenery.hxx | 2 ++ src/Viewer/fg_os_osgviewer.cxx | 13 ++++++++++++- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Main/fg_os.hxx b/src/Main/fg_os.hxx index 46bc235a7..70ffb1b6c 100644 --- a/src/Main/fg_os.hxx +++ b/src/Main/fg_os.hxx @@ -59,6 +59,7 @@ enum { KEYMOD_NONE = 0, void fgOSInit(int* argc, char** argv); void fgOSOpenWindow(bool stencil); +void fgOSCloseWindow(); void fgOSFullScreen(); int fgOSMainLoop(); void fgOSExit(int code); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 26ac132ab..bb3a6457e 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -391,6 +391,7 @@ int fgMainInit( int argc, char **argv ) { // pass control off to the master event handler int result = fgOSMainLoop(); + fgOSCloseWindow(); // clean up here; ensure we null globals to avoid // confusing the atexit() handler diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index 47a08763e..a9dd67cdc 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -379,9 +379,17 @@ bool FGScenery::scenery_available(const SGGeod& position, double range_m) return false; } +static osg::ref_ptr pager; + SceneryPager* FGScenery::getPagerSingleton() { - static osg::ref_ptr pager = new SceneryPager; + if (!pager) + pager = new SceneryPager; return pager.get(); } +void FGScenery::resetPagerSingleton() +{ + pager = NULL; +} + diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index e6a2d7051..be4ed4e60 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -119,6 +119,8 @@ public: // Static because access to the pager is needed before the rest of // the scenery is initialized. static flightgear::SceneryPager* getPagerSingleton(); + static void resetPagerSingleton(); + flightgear::SceneryPager* getPager() { return _pager.get(); } }; diff --git a/src/Viewer/fg_os_osgviewer.cxx b/src/Viewer/fg_os_osgviewer.cxx index e48e940c2..01c646cd8 100644 --- a/src/Viewer/fg_os_osgviewer.cxx +++ b/src/Viewer/fg_os_osgviewer.cxx @@ -386,6 +386,15 @@ void fgOSInit(int* argc, char** argv) WindowSystemAdapter::setWSA(new WindowSystemAdapter); } +void fgOSCloseWindow() +{ + FGScenery::resetPagerSingleton(); + mainCamera = NULL; + flightgear::CameraGroup::setDefault(NULL); + WindowSystemAdapter::setWSA(NULL); + viewer = NULL; +} + void fgOSFullScreen() { std::vector windows; @@ -521,7 +530,9 @@ static int _cursor = -1; void fgSetMouseCursor(int cursor) { _cursor = cursor; - + if (!viewer) + return; + std::vector windows; viewer->getWindows(windows); BOOST_FOREACH(osgViewer::GraphicsWindow* gw, windows) { -- 2.39.5