diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-11 11:42:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-11 11:42:17 +0200 |
commit | 200b9cde88da485659a6376266af8e9bf7be186f (patch) | |
tree | 552a7fa28a8078e44fb545f8ac6a459d32516bb8 /platform/web/web_main.cpp | |
parent | c658fa8b77eb701ddb504cba14fe2c966b7bb105 (diff) | |
parent | 27f22b29f866d5cd807e70289ab771dabc79207c (diff) |
Merge pull request #65644 from Faless/web/4.x_misc_alpha_fixes
[Web] Small fixes and enhancements.
Diffstat (limited to 'platform/web/web_main.cpp')
-rw-r--r-- | platform/web/web_main.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/platform/web/web_main.cpp b/platform/web/web_main.cpp index 0f4411727a..287fe48c4d 100644 --- a/platform/web/web_main.cpp +++ b/platform/web/web_main.cpp @@ -55,6 +55,18 @@ void cleanup_after_sync() { emscripten_set_main_loop(exit_callback, -1, false); } +void early_cleanup() { + emscripten_cancel_main_loop(); // After this, we can exit! + int exit_code = OS_Web::get_singleton()->get_exit_code(); + memdelete(os); + os = nullptr; + emscripten_force_exit(exit_code); // No matter that we call cancel_main_loop, regular "exit" will not work, forcing. +} + +void early_cleanup_sync() { + emscripten_set_main_loop(early_cleanup, -1, false); +} + void main_loop_callback() { uint64_t current_ticks = os->get_ticks_usec(); @@ -87,7 +99,19 @@ extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) { // We must override main when testing is enabled TEST_MAIN_OVERRIDE - Main::setup(argv[0], argc - 1, &argv[1]); + Error err = Main::setup(argv[0], argc - 1, &argv[1]); + + // 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. + godot_js_os_finish_async(early_cleanup_sync); + return exit_code; + } // Ease up compatibility. ResourceLoader::set_abort_on_missing_resources(false); |