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
// idle handler
osg::ref_ptr<flightgear::FGEventHandler> 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();
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<simgear::SGTerraSync*>(subsystemManger->get_subsystem("terrasync"));
auto terra_sync = subsystemManger->get_subsystem<simgear::SGTerraSync>();
if (terra_sync) {
terra_sync->setRoot(globals->get_props());
}

View file

@ -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,7 +419,7 @@ 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);
@ -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();

View file

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

View file

@ -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);

View file

@ -98,6 +98,7 @@ 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);