]> git.mxchange.org Git - flightgear.git/commitdiff
Close dialogs on GUI shutdown
authorJames Turner <zakalawe@mac.com>
Sun, 16 Mar 2014 22:52:55 +0000 (22:52 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 16 Mar 2014 22:52:55 +0000 (22:52 +0000)
- avoids orphaned dialogs on reset
- requires some guards in NasalSys since Nasal is shutdown first, but
  dialogs can have Nasal modules.

src/GUI/new_gui.cxx
src/GUI/new_gui.hxx
src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index 66f4a115a10c244fb68856736b68230fa6f1fffb..d2eb8b14024b180b6464cab10619e9ff0cb5967b 100644 (file)
@@ -88,6 +88,12 @@ NewGUI::init ()
 void
 NewGUI::shutdown()
 {
+    DialogDict::iterator it = _active_dialogs.begin();
+    for (; it != _active_dialogs.end(); ++it) {
+        delete it->second;
+    }
+    _active_dialogs.clear();
+    
     fgUntie("/sim/menubar/visibility");
     _menubar.reset();
     _dialog_props.clear();
@@ -129,7 +135,7 @@ NewGUI::createMenuBarImplementation()
 void
 NewGUI::reset (bool reload)
 {
-    map<string,FGDialog *>::iterator iter;
+    DialogDict::iterator iter;
     string_list openDialogs;
     // close all open dialogs and remember them ...
     for (iter = _active_dialogs.begin(); iter != _active_dialogs.end(); ++iter)
index 1ab1361c8f86ebdb5fa60e15f91bdb12484b2e51..a0e4e69af6b963fddd6b03ff6f8074085bf6f8c8 100644 (file)
@@ -223,7 +223,8 @@ private:
 
     std::auto_ptr<FGMenuBar> _menubar;
     FGDialog * _active_dialog;
-    std::map<std::string,FGDialog *> _active_dialogs;
+    typedef std::map<std::string,FGDialog *> DialogDict;
+    DialogDict _active_dialogs;
   
     typedef std::map<std::string, SGPath> NamePathDict;
     // mapping from dialog names to the corresponding XML property list
index e658ccc5561fcc2a8f10f2016bc8238ab5922816..ae5cbe59fec47e127d8bd6d0a5cb9f9785cebf05 100644 (file)
@@ -201,7 +201,8 @@ static char* readfile(const char* file, int* lenOut)
     return buf;
 }
 
-FGNasalSys::FGNasalSys()
+FGNasalSys::FGNasalSys() :
+    _inited(false)
 {
     nasalSys = this;
     _context = 0;
@@ -249,6 +250,9 @@ naRef FGNasalSys::callMethod(naRef code, naRef self, int argc, naRef* args, naRe
 
 FGNasalSys::~FGNasalSys()
 {
+    if (_inited) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Nasal was not shutdown");
+    }
     nasalSys = 0;
 }
 
@@ -732,6 +736,9 @@ void FGNasalSys::setCmdArg(SGPropertyNode* aNode)
 
 void FGNasalSys::init()
 {
+    if (_inited) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "duplicate init of Nasal");
+    }
     int i;
 
     _context = naNewContext();
@@ -803,10 +810,16 @@ void FGNasalSys::init()
     // now Nasal modules are loaded, we can do some delayed work
     postinitNasalPositioned(_globals, _context);
     postinitNasalGUI(_globals, _context);
+    
+    _inited = true;
 }
 
 void FGNasalSys::shutdown()
 {
+    if (!_inited) {
+        return;
+    }
+    
     shutdownNasalPositioned();
     
     map<int, FGNasalListener *>::iterator it, end = _listener.end();
@@ -837,7 +850,7 @@ void FGNasalSys::shutdown()
     _globals = naNil();    
     
     naGC();
-    
+    _inited = false;
 }
 
 naRef FGNasalSys::wrappedPropsNode(SGPropertyNode* aProps)
@@ -1085,6 +1098,12 @@ bool FGNasalSys::createModule(const char* moduleName, const char* fileName,
 
 void FGNasalSys::deleteModule(const char* moduleName)
 {
+    if (!_inited) {
+        // can occur on shutdown due to us being shutdown first, but other
+        // subsystems having Nasal objects.
+        return;
+    }
+    
     naContext ctx = naNewContext();
     naRef modname = naNewString(ctx);
     naStr_fromdata(modname, (char*)moduleName, strlen(moduleName));
index d4680f1398ae9d06f6fc80b5a5ce681fb8ea1b73..8915c38bf9f374de30c27df5379fa84fd5dfdafe 100644 (file)
@@ -172,6 +172,7 @@ private:
     naRef parse(const char* filename, const char* buf, int len);
     naRef genPropsModule();
 
+    bool _inited;
     naContext _context;
     naRef _globals,
           _string;