From 4a485adcf3b9fe73cbeb0d681bad66ff1ad626a2 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 29 Apr 2020 14:55:37 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20crash=20on=20=E2=80=94show-aircraft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change how we return, so QApplication doesn’t explode. exit() is not a happy thing for QApplication. Ticket: https://sourceforge.net/p/flightgear/codetickets/2139/ --- src/Main/fg_init.cxx | 4 +++- src/Main/main.cxx | 4 +++- src/Main/options.cxx | 7 +++++-- src/Main/options.hxx | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 08f5a4d8d..fe3a9b801 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -717,7 +717,9 @@ void fgInitAircraftPaths(bool reinit) int fgInitAircraft(bool reinit) { if (!reinit) { - flightgear::Options::sharedInstance()->initAircraft(); + auto r = flightgear::Options::sharedInstance()->initAircraft(); + if (r == flightgear::FG_OPTIONS_SHOW_AIRCRAFT) + return r; } FindAndCacheAircraft f(globals->get_props()); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 955cc949c..5cec93dca 100755 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -647,7 +647,9 @@ int fgMainInit( int argc, char **argv ) configResult = fgInitAircraft(false); if (configResult == flightgear::FG_OPTIONS_ERROR) { return EXIT_FAILURE; - } else if (configResult == flightgear::FG_OPTIONS_EXIT) { + } else if ((configResult == flightgear::FG_OPTIONS_EXIT) || + (configResult == flightgear::FG_OPTIONS_SHOW_AIRCRAFT)) + { return EXIT_SUCCESS; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 75c46a69c..255383f1d 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -2211,7 +2211,7 @@ void Options::initPaths() } -void Options::initAircraft() +OptionResult Options::initAircraft() { string aircraft; if (isOptionSet("aircraft")) { @@ -2246,7 +2246,8 @@ void Options::initAircraft() aircraft_paths.end()); fgShowAircraft(path_list); - exit(0); + // this is to indicate that we did show it + return FG_OPTIONS_SHOW_AIRCRAFT; } if (isOptionSet("aircraft-dir")) { @@ -2268,6 +2269,8 @@ void Options::initAircraft() // can't validate this until the -set.xml is parsed fgSetString("/sim/aircraft-state", stateName); } + + return FG_OPTIONS_OK; } void Options::processArgResult(int result) diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 4cd3bd995..c4a564563 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -130,7 +130,7 @@ public: /** * init the aircraft options */ - void initAircraft(); + OptionResult initAircraft(); /** * should defualt configuration files be loaded and processed or not?