diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 8e566ee19..b72976677 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1293,20 +1293,26 @@ void fgStartNewReset() // preserve the event handler; re-creating it would entail fixing the // idle handler osg::ref_ptr eventHandler = render->getEventHandler(); - + // tell the event handler to drop properties, etc + eventHandler->clear(); + globals->set_renderer(NULL); globals->set_matlib(NULL); - + + flightgear::unregisterMainLoopProperties(); + FGReplayData::resetStatisticsProperties(); + simgear::clearEffectCache(); simgear::SGModelLib::resetPropertyRoot(); simgear::GlobalParticleCallback::setSwitch(NULL); - simgear::UniformFactory::instance()->reset(); - + simgear::UniformFactory::instance()->reset(); + + flightgear::addons::AddonManager::reset(); + globals->resetPropertyRoot(); // otherwise channels are duplicated globals->get_channel_options_list()->clear(); - flightgear::addons::AddonManager::reset(); flightgear::addons::AddonManager::createInstance(); fgInitConfig(0, NULL, true); @@ -1359,8 +1365,6 @@ void fgStartNewReset() fgOSResetProperties(); - FGReplayData::resetStatisticsProperties(); - // init some things manually // which do not follow the regular init pattern @@ -1370,7 +1374,7 @@ void fgStartNewReset() globals->set_matlib( new SGMaterialLib ); // terra-sync needs the property tree root, pass it back in - auto terra_sync = static_cast(subsystemManger->get_subsystem("terrasync")); + auto terra_sync = subsystemManger->get_subsystem(); if (terra_sync) { terra_sync->setRoot(globals->get_props()); } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 9ecf07b29..631f79e8c 100755 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -267,7 +267,9 @@ static void checkOpenGLVersion() } // of three parts } -static void registerMainLoop() +namespace flightgear { + +void registerMainLoop() { // stash current frame signal property frame_signal = fgGetNode("/sim/signals/frame", true); @@ -276,6 +278,15 @@ static void registerMainLoop() fgRegisterIdleHandler( fgMainLoop ); } +void unregisterMainLoopProperties() +{ + frame_signal.reset(); + nasal_gc_threaded.reset(); + nasal_gc_threaded_wait.reset(); +} + +} // namespace flightgear + // This is the top level master main function that is registered as // our idle function @@ -408,8 +419,8 @@ static void fgIdleFunction ( void ) { // We've finished all our initialization steps, from now on we // run the main loop. fgSetBool("sim/sceneryloaded", false); - registerMainLoop(); - + flightgear::registerMainLoop(); + ngccn = new simgear::Notifications::NasalGarbageCollectionConfigurationNotification(nasal_gc_threaded->getBoolValue(), nasal_gc_threaded_wait->getBoolValue()); simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(*ngccn); simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(mln_started); @@ -739,7 +750,8 @@ int fgMainInit( int argc, char **argv ) // pass control off to the master event handler int result = fgOSMainLoop(); - frame_signal.clear(); + flightgear::unregisterMainLoopProperties(); + fgOSCloseWindow(); fgShutdownHome(); diff --git a/src/Main/main.hxx b/src/Main/main.hxx index 8165aadde..f2ee524cd 100644 --- a/src/Main/main.hxx +++ b/src/Main/main.hxx @@ -27,4 +27,11 @@ void fgResetIdleState(); extern std::string hostname; +namespace flightgear { + +void registerMainLoop(); +void unregisterMainLoopProperties(); + +} // namespace flightgear + #endif diff --git a/src/Viewer/FGEventHandler.cxx b/src/Viewer/FGEventHandler.cxx index 652f005ea..b62acc27e 100644 --- a/src/Viewer/FGEventHandler.cxx +++ b/src/Viewer/FGEventHandler.cxx @@ -55,6 +55,12 @@ FGEventHandler::FGEventHandler() : _print = fgGetNode("/sim/rendering/print-statistics", true); } +void FGEventHandler::clear() +{ + _display.clear(); + _print.clear(); +} + void FGEventHandler::reset() { _display = fgGetNode("/sim/rendering/on-screen-statistics", true); diff --git a/src/Viewer/FGEventHandler.hxx b/src/Viewer/FGEventHandler.hxx index 391023643..d40fffb89 100644 --- a/src/Viewer/FGEventHandler.hxx +++ b/src/Viewer/FGEventHandler.hxx @@ -98,7 +98,8 @@ public: void setResizable(bool _resizable) { resizable = _resizable; } void reset(); - + void clear(); + static int translateKey(const osgGA::GUIEventAdapter& ea); static int translateModifiers(const osgGA::GUIEventAdapter& ea); protected: