From 36840f3fe0736d5aeea5f218a8eac81eb52ef787 Mon Sep 17 00:00:00 2001 From: Lomash Gupta Date: Sat, 5 Oct 2019 12:57:07 -0400 Subject: [PATCH 1/3] fixed gExitCode --- src/openrct2-cli/Cli.cpp | 6 ++++-- src/openrct2-ui/Ui.cpp | 13 +++++++------ src/openrct2/Context.cpp | 3 ++- src/openrct2/OpenRCT2.cpp | 1 - src/openrct2/OpenRCT2.h | 3 --- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/openrct2-cli/Cli.cpp b/src/openrct2-cli/Cli.cpp index a063be9185..cf6a55b04d 100644 --- a/src/openrct2-cli/Cli.cpp +++ b/src/openrct2-cli/Cli.cpp @@ -27,7 +27,9 @@ int main(int argc, const char** argv) // Run OpenRCT2 with a plain context auto context = CreateContext(); - context->RunOpenRCT2(argc, argv); + if((context->RunOpenRCT2(argc, argv)) == EXIT_SUCCESS) { + return EXIT_SUCCESS; + } } - return gExitCode; + return EXIT_FAILURE; } diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index 22ebaeada3..08bd347916 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -38,6 +38,7 @@ int NormalisedMain(int argc, const char** argv) int main(int argc, const char** argv) #endif { + std::unique_ptr context; int runGame = cmdline_run(argv, argc); core_init(); RegisterBitmapReader(); @@ -46,8 +47,7 @@ int main(int argc, const char** argv) if (gOpenRCT2Headless) { // Run OpenRCT2 with a plain context - auto context = CreateContext(); - context->RunOpenRCT2(argc, argv); + context = CreateContext(); } else { @@ -55,12 +55,13 @@ int main(int argc, const char** argv) auto env = to_shared(CreatePlatformEnvironment()); auto audioContext = to_shared(CreateAudioContext()); auto uiContext = to_shared(CreateUiContext(env)); - auto context = CreateContext(env, audioContext, uiContext); - - context->RunOpenRCT2(argc, argv); + context = CreateContext(env, audioContext, uiContext); + } + if (context->RunOpenRCT2(argc, argv) == EXIT_SUCCESS) { + return EXIT_SUCCESS; } } - return gExitCode; + return EXIT_FAILURE; } #ifdef __ANDROID__ diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 987a4a7249..34acc7788d 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -243,8 +243,9 @@ namespace OpenRCT2 if (Initialise()) { Launch(); + return EXIT_SUCCESS; } - return gExitCode; + return EXIT_FAILURE; } void WriteLine(const std::string& s) override diff --git a/src/openrct2/OpenRCT2.cpp b/src/openrct2/OpenRCT2.cpp index 30dd4abcae..a6212ef2e3 100644 --- a/src/openrct2/OpenRCT2.cpp +++ b/src/openrct2/OpenRCT2.cpp @@ -9,7 +9,6 @@ #include "OpenRCT2.h" -int32_t gExitCode; int32_t gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; utf8 gOpenRCT2StartupActionPath[512] = { 0 }; utf8 gExePath[MAX_PATH]; diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index ac57ac4e17..fea147ec55 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -34,9 +34,6 @@ enum SCREEN_FLAGS_EDITOR = (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER), }; -/** The exit code for OpenRCT2 when it exits. */ -extern int32_t gExitCode; - extern int32_t gOpenRCT2StartupAction; extern utf8 gOpenRCT2StartupActionPath[512]; extern utf8 gExePath[MAX_PATH]; From 0165261ac08fa2f58fe15561e36a5244fe8dee7d Mon Sep 17 00:00:00 2001 From: Lomash Gupta Date: Sat, 5 Oct 2019 15:26:55 -0400 Subject: [PATCH 2/3] Fix #9477: Fix process exit code always being zero - Replaced gExitCode occurences with EXIT_SUCCESS and EXIT_FAILURE - Removed global declaration of gExitCode --- src/openrct2-cli/Cli.cpp | 11 +++++++---- src/openrct2-ui/Ui.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/openrct2-cli/Cli.cpp b/src/openrct2-cli/Cli.cpp index cf6a55b04d..69b0b55f10 100644 --- a/src/openrct2-cli/Cli.cpp +++ b/src/openrct2-cli/Cli.cpp @@ -18,6 +18,7 @@ using namespace OpenRCT2; */ int main(int argc, const char** argv) { + int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); core_init(); if (runGame == 1) @@ -27,9 +28,11 @@ int main(int argc, const char** argv) // Run OpenRCT2 with a plain context auto context = CreateContext(); - if((context->RunOpenRCT2(argc, argv)) == EXIT_SUCCESS) { - return EXIT_SUCCESS; - } + rc = context->RunOpenRCT2(argc, argv); } - return EXIT_FAILURE; + else if (runGame == -1) + { + rc = EXIT_FAILURE; + } + return rc; } diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index 08bd347916..c3fc9324c7 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -39,6 +39,7 @@ int main(int argc, const char** argv) #endif { std::unique_ptr context; + int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); core_init(); RegisterBitmapReader(); @@ -57,11 +58,13 @@ int main(int argc, const char** argv) auto uiContext = to_shared(CreateUiContext(env)); context = CreateContext(env, audioContext, uiContext); } - if (context->RunOpenRCT2(argc, argv) == EXIT_SUCCESS) { - return EXIT_SUCCESS; - } + rc = context->RunOpenRCT2(argc, argv); } - return EXIT_FAILURE; + else if (runGame == -1) + { + rc = EXIT_FAILURE; + } + return rc; } #ifdef __ANDROID__ From c87e1ff9b6049f2bb0650106f5b3b33553352b8f Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 19 Jan 2020 18:48:50 -0300 Subject: [PATCH 3/3] Use EXITCODE enum on game startup --- src/openrct2-cli/Cli.cpp | 5 +++-- src/openrct2-ui/Ui.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openrct2-cli/Cli.cpp b/src/openrct2-cli/Cli.cpp index 69b0b55f10..6491a2d2b7 100644 --- a/src/openrct2-cli/Cli.cpp +++ b/src/openrct2-cli/Cli.cpp @@ -9,6 +9,7 @@ #include #include +#include #include using namespace OpenRCT2; @@ -21,7 +22,7 @@ int main(int argc, const char** argv) int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); core_init(); - if (runGame == 1) + if (runGame == EXITCODE_CONTINUE) { gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; @@ -30,7 +31,7 @@ int main(int argc, const char** argv) auto context = CreateContext(); rc = context->RunOpenRCT2(argc, argv); } - else if (runGame == -1) + else if (runGame == EXITCODE_FAIL) { rc = EXIT_FAILURE; } diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index c3fc9324c7..ebd5bf2478 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ int main(int argc, const char** argv) int runGame = cmdline_run(argv, argc); core_init(); RegisterBitmapReader(); - if (runGame == 1) + if (runGame == EXITCODE_CONTINUE) { if (gOpenRCT2Headless) { @@ -60,7 +61,7 @@ int main(int argc, const char** argv) } rc = context->RunOpenRCT2(argc, argv); } - else if (runGame == -1) + else if (runGame == EXITCODE_FAIL) { rc = EXIT_FAILURE; }