From 381919451d343e12e558a66528b99e831fbf0fa6 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 22 Apr 2020 10:56:54 +0100 Subject: [PATCH] Fix for reset crash: https://sourceforge.net/p/flightgear/codetickets/2217/ This requires a matching Simgear change, but ensure all places tolerate Nasal subsystem being gone, since this occurs during reset. --- src/AIModel/AIManager.cxx | 2 +- src/GUI/FileDialog.cxx | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 4625572ff..5a2d2dca0 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -86,7 +86,7 @@ public: FGNasalSys* nasalSys = globals->get_subsystem(); - if (!nasalSys) + if (!nasalSys) // happens during shutdown / reset return; std::string moduleName = "scenario_" + _internalName; diff --git a/src/GUI/FileDialog.cxx b/src/GUI/FileDialog.cxx index 7b5909858..9604a98b5 100644 --- a/src/GUI/FileDialog.cxx +++ b/src/GUI/FileDialog.cxx @@ -96,15 +96,15 @@ public: func(f), object(obj) { - FGNasalSys* sys = static_cast(globals->get_subsystem("nasal")); + FGNasalSys* sys = globals->get_subsystem(); _gcKeys[0] = sys->gcSave(f); _gcKeys[1] = sys->gcSave(obj); } - virtual void onFileDialogDone(FGFileDialog* instance, const SGPath& aPath) + void onFileDialogDone(FGFileDialog* instance, const SGPath& aPath) override { - FGNasalSys* sys = static_cast(globals->get_subsystem("nasal")); - + FGNasalSys* sys = globals->get_subsystem(); + naContext ctx = naNewContext(); naRef args[1]; args[0] = nasal::to_nasal(ctx, aPath); @@ -115,7 +115,10 @@ public: ~NasalCallback() { - FGNasalSys* sys = static_cast(globals->get_subsystem("nasal")); + FGNasalSys* sys = globals->get_subsystem(); + if (!sys) // happens during Nasal shutdown on reset + return; + sys->gcRelease(_gcKeys[0]); sys->gcRelease(_gcKeys[1]); }