1
0
Fork 0

Improve reset main-loop interaction.

Actually remove our main-loop properties, and clear them from the
EventHandler, so we don’t report them as leaked properties.
This commit is contained in:
James Turner 2020-08-11 18:32:36 +01:00
parent 3b5721d77e
commit c913b752fc
5 changed files with 43 additions and 13 deletions

View file

@ -1293,20 +1293,26 @@ void fgStartNewReset()
// preserve the event handler; re-creating it would entail fixing the // preserve the event handler; re-creating it would entail fixing the
// idle handler // idle handler
osg::ref_ptr<flightgear::FGEventHandler> eventHandler = render->getEventHandler(); osg::ref_ptr<flightgear::FGEventHandler> eventHandler = render->getEventHandler();
// tell the event handler to drop properties, etc
eventHandler->clear();
globals->set_renderer(NULL); globals->set_renderer(NULL);
globals->set_matlib(NULL); globals->set_matlib(NULL);
flightgear::unregisterMainLoopProperties();
FGReplayData::resetStatisticsProperties();
simgear::clearEffectCache(); simgear::clearEffectCache();
simgear::SGModelLib::resetPropertyRoot(); simgear::SGModelLib::resetPropertyRoot();
simgear::GlobalParticleCallback::setSwitch(NULL); simgear::GlobalParticleCallback::setSwitch(NULL);
simgear::UniformFactory::instance()->reset(); simgear::UniformFactory::instance()->reset();
flightgear::addons::AddonManager::reset();
globals->resetPropertyRoot(); globals->resetPropertyRoot();
// otherwise channels are duplicated // otherwise channels are duplicated
globals->get_channel_options_list()->clear(); globals->get_channel_options_list()->clear();
flightgear::addons::AddonManager::reset();
flightgear::addons::AddonManager::createInstance(); flightgear::addons::AddonManager::createInstance();
fgInitConfig(0, NULL, true); fgInitConfig(0, NULL, true);
@ -1359,8 +1365,6 @@ void fgStartNewReset()
fgOSResetProperties(); fgOSResetProperties();
FGReplayData::resetStatisticsProperties();
// init some things manually // init some things manually
// which do not follow the regular init pattern // which do not follow the regular init pattern
@ -1370,7 +1374,7 @@ void fgStartNewReset()
globals->set_matlib( new SGMaterialLib ); globals->set_matlib( new SGMaterialLib );
// terra-sync needs the property tree root, pass it back in // terra-sync needs the property tree root, pass it back in
auto terra_sync = static_cast<simgear::SGTerraSync*>(subsystemManger->get_subsystem("terrasync")); auto terra_sync = subsystemManger->get_subsystem<simgear::SGTerraSync>();
if (terra_sync) { if (terra_sync) {
terra_sync->setRoot(globals->get_props()); terra_sync->setRoot(globals->get_props());
} }

View file

@ -267,7 +267,9 @@ static void checkOpenGLVersion()
} // of three parts } // of three parts
} }
static void registerMainLoop() namespace flightgear {
void registerMainLoop()
{ {
// stash current frame signal property // stash current frame signal property
frame_signal = fgGetNode("/sim/signals/frame", true); frame_signal = fgGetNode("/sim/signals/frame", true);
@ -276,6 +278,15 @@ static void registerMainLoop()
fgRegisterIdleHandler( fgMainLoop ); 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 // This is the top level master main function that is registered as
// our idle function // our idle function
@ -408,8 +419,8 @@ static void fgIdleFunction ( void ) {
// We've finished all our initialization steps, from now on we // We've finished all our initialization steps, from now on we
// run the main loop. // run the main loop.
fgSetBool("sim/sceneryloaded", false); fgSetBool("sim/sceneryloaded", false);
registerMainLoop(); flightgear::registerMainLoop();
ngccn = new simgear::Notifications::NasalGarbageCollectionConfigurationNotification(nasal_gc_threaded->getBoolValue(), nasal_gc_threaded_wait->getBoolValue()); 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(*ngccn);
simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(mln_started); 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 // pass control off to the master event handler
int result = fgOSMainLoop(); int result = fgOSMainLoop();
frame_signal.clear(); flightgear::unregisterMainLoopProperties();
fgOSCloseWindow(); fgOSCloseWindow();
fgShutdownHome(); fgShutdownHome();

View file

@ -27,4 +27,11 @@ void fgResetIdleState();
extern std::string hostname; extern std::string hostname;
namespace flightgear {
void registerMainLoop();
void unregisterMainLoopProperties();
} // namespace flightgear
#endif #endif

View file

@ -55,6 +55,12 @@ FGEventHandler::FGEventHandler() :
_print = fgGetNode("/sim/rendering/print-statistics", true); _print = fgGetNode("/sim/rendering/print-statistics", true);
} }
void FGEventHandler::clear()
{
_display.clear();
_print.clear();
}
void FGEventHandler::reset() void FGEventHandler::reset()
{ {
_display = fgGetNode("/sim/rendering/on-screen-statistics", true); _display = fgGetNode("/sim/rendering/on-screen-statistics", true);

View file

@ -98,7 +98,8 @@ public:
void setResizable(bool _resizable) { resizable = _resizable; } void setResizable(bool _resizable) { resizable = _resizable; }
void reset(); void reset();
void clear();
static int translateKey(const osgGA::GUIEventAdapter& ea); static int translateKey(const osgGA::GUIEventAdapter& ea);
static int translateModifiers(const osgGA::GUIEventAdapter& ea); static int translateModifiers(const osgGA::GUIEventAdapter& ea);
protected: protected: