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.
{
// 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()
// 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" );
simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
_listener = new ScenerySwitchListener(this);
+
+ // Toggle the setup flag.
+ _inited = true;
}
void FGScenery::shutdown()
models_branch = NULL;
aircraft_branch = NULL;
particles_branch = NULL;
+
+ // Toggle the setup flag.
+ _inited = false;
}
flightgear::SceneryPager* getPager() { return _pager.get(); }
static const char* subsystemName() { return "scenery"; }
+
+private:
+ // The state of the scene graph.
+ bool _inited;
};