1
0
Fork 0

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
This commit is contained in:
James Turner 2021-01-04 14:46:01 +00:00
parent 6caadf2450
commit 64b03b70a8
3 changed files with 36 additions and 0 deletions

View file

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

View file

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

View file

@ -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<SGSubsystemMgr::MAX_GROUPS; ++g) {