From: Edward d'Auvergne Date: Tue, 3 May 2016 13:14:53 +0000 (+0200) Subject: Prevention of the creation of multiple OSG scene graph roots. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ab2c01c6a97acb132082ac0ff9140a9f463c31d0;p=flightgear.git Prevention of the creation of multiple OSG scene graph roots. As the scenery manager's init() function is called twice on start up, two OSG scene graph roots would be created. A number of scene graph branches would be initalised on the first root, but then be lost as the second is created. This fixes the precipitation branch, for example. --- diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index 9b9df333f..48334337e 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -286,6 +286,9 @@ FGScenery::FGScenery() : { // keep reference to pager singleton, so it cannot be destroyed while FGScenery lives _pager = FGScenery::getPagerSingleton(); + + // Initialise the state of the scene graph. + _inited = false; } FGScenery::~FGScenery() @@ -296,6 +299,10 @@ FGScenery::~FGScenery() // Initialize the Scenery Management system void FGScenery::init() { + // Already set up. + if (_inited) + return; + // Scene graph root scene_graph = new osg::Switch; scene_graph->setName( "FGScenery" ); @@ -334,6 +341,9 @@ void FGScenery::init() { simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true)); _listener = new ScenerySwitchListener(this); + + // Toggle the setup flag. + _inited = true; } void FGScenery::shutdown() @@ -343,6 +353,9 @@ void FGScenery::shutdown() models_branch = NULL; aircraft_branch = NULL; particles_branch = NULL; + + // Toggle the setup flag. + _inited = false; } diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index 593707d14..55176ca55 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -131,6 +131,10 @@ public: flightgear::SceneryPager* getPager() { return _pager.get(); } static const char* subsystemName() { return "scenery"; } + +private: + // The state of the scene graph. + bool _inited; };