From 64b03b70a8db18d84a3df2538180d70069091495 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 4 Jan 2021 14:46:01 +0000 Subject: [PATCH] Clear ATCDialog instance on reset Showed up as a variety of crashes on Sentry, due to a stale instance of this object hanging around after reset. Sentry-Id:FLIGHTGEAR-T5 --- src/ATC/atcdialog.cxx | 17 +++++++++++++++++ src/ATC/atcdialog.hxx | 14 ++++++++++++++ src/Main/fg_init.cxx | 5 +++++ 3 files changed, 36 insertions(+) diff --git a/src/ATC/atcdialog.cxx b/src/ATC/atcdialog.cxx index a79778340..7466f6b77 100644 --- a/src/ATC/atcdialog.cxx +++ b/src/ATC/atcdialog.cxx @@ -214,6 +214,14 @@ void FGATCDialogNew::init() { globals->get_props()->setIntValue("/sim/atc/transmission-num", -1); } +void FGATCDialogNew::shutdown() +{ + auto commands = globals->get_commands(); + commands->removeCommand("ATC-dialog"); + commands->removeCommand("ATC-freq-search"); + commands->removeCommand("ATC-freq-display"); +} + // Display the ATC popup dialog box with options relevant to the users current situation. // // So, the first thing we need to do is check the frequency that our pilot's nav radio @@ -242,6 +250,15 @@ void FGATCDialogNew::PopupDialog() { return; } +void FGATCDialogNew::hackyReset() +{ + if (_instance) { + _instance->shutdown(); + delete _instance; + _instance = nullptr; + } +} + void FGATCDialogNew::update(double dt) { // double onBoardRadioFreq0 = // fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz"); diff --git a/src/ATC/atcdialog.hxx b/src/ATC/atcdialog.hxx index 18cfb162f..c223787be 100644 --- a/src/ATC/atcdialog.hxx +++ b/src/ATC/atcdialog.hxx @@ -35,6 +35,11 @@ class NewGUI; class SGPropertyNode; +/** + * despite looking like a subsystem, this is not, at the moment. + * So don't assume it has subsystem semantics or behaviour. + * For 'next' we're fixing this, but it's too complex a change for 2020.3 + */ class FGATCDialogNew { private: @@ -52,6 +57,7 @@ public: void frequencyDisplay(const std::string& ident); void init(); + void shutdown(); void update(double dt); void PopupDialog(); @@ -63,6 +69,14 @@ public: return true; } + /** + * hacky fix for various crashes on reset: give a way to reset instance + * back to null-ptr, so that we get a new instance created. + * Without this, we crash in various exciting ways due to stale pointers + * + */ + static void hackyReset(); + // Generate new instance of FGATCDialogNew if it hasn't yet been generated // Call constructor and init() functions // If it has been generated, will return that instance diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index a575257d3..9a82a9586 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1265,6 +1265,11 @@ void fgStartNewReset() subsystemManger->shutdown(); subsystemManger->unbind(); + + // hack fix for many reset crashes relating to the static instance + // of this class. Will be fixed better for future versions by making + // this a proper subsystem. + FGATCDialogNew::hackyReset(); // remove most subsystems, with a few exceptions. for (int g=0; g