Fix crash if selected settings window does not open

If one tries to open a setting window, the emulator grabs the input.
However, if opening the window then fails (most commonly because it is
joystick settings window, and there are no online nor offline gamepads)
the grab needs to be undone because otherwise the grab will point to
freed memory. The destructor would undo it, except failure to open window
triggers exit from constructor by exception, in which case destructor
will not run.

Bug reported on IRC.
This commit is contained in:
Ilari Liusvaara 2019-06-24 22:16:15 +03:00
parent d4003f9d6c
commit 88160be520

View file

@ -146,7 +146,14 @@ namespace
if(singletab) {
//If this throws, let it throw through.
settings_tab* t = singletab->create(this, inst);
settings_tab* t;
try {
t = singletab->create(this, inst);
} catch(...) {
//Release the key grab, so we do not crash.
inst.keyboard->set_exclusive(NULL);
throw;
}
top_s->Add(t, 1, wxGROW);
t->set_notify([this]() { this->on_notify(); });
tabs.push_back(t);
@ -166,8 +173,11 @@ namespace
created++;
}
top_s->Add(tabset, 1, wxGROW);
if(!created)
if(!created) {
//Release the key grab, so we do not crash.
inst.keyboard->set_exclusive(NULL);
throw std::runtime_error("Nothing to configure here, move along");
}
}
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);