Close dialogs on GUI shutdown
- avoids orphaned dialogs on reset - requires some guards in NasalSys since Nasal is shutdown first, but dialogs can have Nasal modules.
This commit is contained in:
parent
2d5d43a57d
commit
070dba29f9
4 changed files with 31 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -172,6 +172,7 @@ private:
|
|||
naRef parse(const char* filename, const char* buf, int len);
|
||||
naRef genPropsModule();
|
||||
|
||||
bool _inited;
|
||||
naContext _context;
|
||||
naRef _globals,
|
||||
_string;
|
||||
|
|
Loading…
Reference in a new issue