1
0
Fork 0

Change how fatalMessageBoxThenExit works

This avoids crashing when using Qt : we cannot call exit() safely since
QGuiApplication won’t shut down correctly. Instead throw a special
marker object and catch this in boostrap.

For an instance of this, see:

https://sourceforge.net/p/flightgear/codetickets/2070/
This commit is contained in:
James Turner 2020-06-24 15:47:56 +01:00
parent 222a96503d
commit ee6f4388ee
3 changed files with 12 additions and 2 deletions

View file

@ -191,7 +191,10 @@ MessageBoxResult fatalMessageBoxWithoutExit(const std::string& caption,
int exitStatus)
{
fatalMessageBoxWithoutExit(caption, msg, moreText);
exit(exitStatus);
// we can't use exit() here or QGuiApplication crashes
// let's instead throw a sepcial exception which we catch
// in boostrap.
throw FatalErrorException{};
}
} // of namespace flightgear

View file

@ -7,6 +7,12 @@
namespace flightgear
{
// special exception class used to signal an exit. Must not inherit
// std::exception or similar, since we want to handle it specially
class FatalErrorException
{
};
enum MessageBoxResult
{
MSG_BOX_OK,

View file

@ -320,9 +320,10 @@ int main ( int argc, char **argv )
flightgear::fatalMessageBoxWithoutExit("Fatal exception", e.what());
} catch (const std::string &s) {
flightgear::fatalMessageBoxWithoutExit("Fatal exception", s);
} catch (const flightgear::FatalErrorException&) {
// we already showed the message box, just carry on to exit
} catch (const char *s) {
std::cerr << "Fatal error (const char*): " << s << std::endl;
} catch (...) {
std::cerr << "Unknown exception in the main loop. Aborting..." << std::endl;
if (errno)