summaryrefslogtreecommitdiffstats
path: root/platform
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-03-06 18:50:35 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-03-08 23:31:24 +0100
commit023dcd44c1e628bb654b5472418d6a346b510a71 (patch)
tree61ae1291ab2b93c2a0de25c4edcc11ee20c3be75 /platform
parentffc41fb76df5922321cdd98cce12715a039629b0 (diff)
downloadredot-engine-023dcd44c1e628bb654b5472418d6a346b510a71.tar.gz
Refactor OS exit code to be `EXIT_SUCCESS` by default
- `Main::setup` early exits (failure or `--help`/`--version`) now consistently return `EXIT_FAILURE` or `EXIT_SUCCESS` on all platforms, instead of 255 on some and a Godot Error code on others. - `Main::start` now returns the exit code, simplifying the handling of early failures. - `Main::iteration` needs to explicit set the exit code in OS if it errors out. - Web and iOS now properly return `OS::get_exit_code()` instead of 0.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/godot_ios.mm11
-rw-r--r--platform/linuxbsd/godot_linuxbsd.cpp13
-rw-r--r--platform/macos/godot_main_macos.mm19
-rw-r--r--platform/web/web_main.cpp16
-rw-r--r--platform/windows/godot_windows.cpp8
5 files changed, 36 insertions, 31 deletions
diff --git a/platform/ios/godot_ios.mm b/platform/ios/godot_ios.mm
index 5e66c8b47b..9d35d43344 100644
--- a/platform/ios/godot_ios.mm
+++ b/platform/ios/godot_ios.mm
@@ -102,15 +102,16 @@ int ios_main(int argc, char **argv) {
Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false);
- if (err == ERR_HELP) { // Returned by --help and --version, so success.
- return 0;
- } else if (err != OK) {
- return 255;
+ if (err != OK) {
+ if (err == ERR_HELP) { // Returned by --help and --version, so success.
+ return EXIT_SUCCESS;
+ }
+ return EXIT_FAILURE;
}
os->initialize_modules();
- return 0;
+ return os->get_exit_code();
}
void ios_finish() {
diff --git a/platform/linuxbsd/godot_linuxbsd.cpp b/platform/linuxbsd/godot_linuxbsd.cpp
index a2b6fbeb25..b0880c86b8 100644
--- a/platform/linuxbsd/godot_linuxbsd.cpp
+++ b/platform/linuxbsd/godot_linuxbsd.cpp
@@ -72,18 +72,19 @@ int main(int argc, char *argv[]) {
char *ret = getcwd(cwd, PATH_MAX);
Error err = Main::setup(argv[0], argc - 1, &argv[1]);
+
if (err != OK) {
free(cwd);
-
if (err == ERR_HELP) { // Returned by --help and --version, so success.
- return 0;
+ return EXIT_SUCCESS;
}
- return 255;
+ return EXIT_FAILURE;
}
- if (Main::start()) {
- os.set_exit_code(EXIT_SUCCESS);
- os.run(); // it is actually the OS that decides how to run
+ if (Main::start() == EXIT_SUCCESS) {
+ os.run();
+ } else {
+ os.set_exit_code(EXIT_FAILURE);
}
Main::cleanup();
diff --git a/platform/macos/godot_main_macos.mm b/platform/macos/godot_main_macos.mm
index 3959fb686c..279d805462 100644
--- a/platform/macos/godot_main_macos.mm
+++ b/platform/macos/godot_main_macos.mm
@@ -69,18 +69,21 @@ int main(int argc, char **argv) {
err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]);
}
- if (err == ERR_HELP) { // Returned by --help and --version, so success.
- return 0;
- } else if (err != OK) {
- return 255;
+ if (err != OK) {
+ if (err == ERR_HELP) { // Returned by --help and --version, so success.
+ return EXIT_SUCCESS;
+ }
+ return EXIT_FAILURE;
}
- bool ok;
+ int ret;
@autoreleasepool {
- ok = Main::start();
+ ret = Main::start();
}
- if (ok) {
- os.run(); // It is actually the OS that decides how to run.
+ if (ret) {
+ os.run();
+ } else {
+ os.set_exit_code(EXIT_FAILURE);
}
@autoreleasepool {
diff --git a/platform/web/web_main.cpp b/platform/web/web_main.cpp
index ad2a801881..04513f6d57 100644
--- a/platform/web/web_main.cpp
+++ b/platform/web/web_main.cpp
@@ -109,24 +109,22 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
// Proper shutdown in case of setup failure.
if (err != OK) {
- int exit_code = (int)err;
- if (err == ERR_HELP) {
- exit_code = 0; // Called with --help.
- }
- os->set_exit_code(exit_code);
// Will only exit after sync.
emscripten_set_main_loop(exit_callback, -1, false);
godot_js_os_finish_async(cleanup_after_sync);
- return exit_code;
+ if (err == ERR_HELP) { // Returned by --help and --version, so success.
+ return EXIT_SUCCESS;
+ }
+ return EXIT_FAILURE;
}
- os->set_exit_code(0);
main_started = true;
// Ease up compatibility.
ResourceLoader::set_abort_on_missing_resources(false);
- Main::start();
+ int ret = Main::start();
+ os->set_exit_code(ret);
os->get_main_loop()->initialize();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_project_manager_hint() && FileAccess::exists("/tmp/preload.zip")) {
@@ -140,5 +138,5 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
// We are inside an animation frame, we want to immediately draw on the newly setup canvas.
main_loop_callback();
- return 0;
+ return os->get_exit_code();
}
diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp
index f86ecd87fb..5f41b4e568 100644
--- a/platform/windows/godot_windows.cpp
+++ b/platform/windows/godot_windows.cpp
@@ -171,13 +171,15 @@ int widechar_main(int argc, wchar_t **argv) {
delete[] argv_utf8;
if (err == ERR_HELP) { // Returned by --help and --version, so success.
- return 0;
+ return EXIT_SUCCESS;
}
- return 255;
+ return EXIT_FAILURE;
}
- if (Main::start()) {
+ if (Main::start() == EXIT_SUCCESS) {
os.run();
+ } else {
+ os.set_exit_code(EXIT_FAILURE);
}
Main::cleanup();