diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-02 12:04:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-02 12:04:50 +0100 |
commit | 92ff4f7877ddbbf97c6170143b07c590ec04487c (patch) | |
tree | ce8dacb7d0f1542a2d88793f9234cdf6a71bf710 | |
parent | efa587ad36a4ff8a465cb7a076d01ce0ce83b71a (diff) | |
parent | 8f6d4eaa31662bbff08fb0a694fb41f74f225b0a (diff) | |
download | redot-engine-92ff4f7877ddbbf97c6170143b07c590ec04487c.tar.gz |
Merge pull request #87836 from stuartcarnie/autoreleasepool
macOS: Use autorelease pools
-rw-r--r-- | platform/macos/display_server_macos.mm | 1 | ||||
-rw-r--r-- | platform/macos/godot_main_macos.mm | 14 | ||||
-rw-r--r-- | platform/macos/os_macos.mm | 24 |
3 files changed, 26 insertions, 13 deletions
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 396b943251..b471fc827b 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -160,6 +160,7 @@ DisplayServerMacOS::WindowID DisplayServerMacOS::_create_window(WindowMode p_mod defer:NO]; ERR_FAIL_NULL_V_MSG(wd.window_object, INVALID_WINDOW_ID, "Can't create a window"); [wd.window_object setWindowID:window_id_counter]; + [wd.window_object setReleasedWhenClosed:NO]; wd.window_view = [[GodotContentView alloc] init]; ERR_FAIL_NULL_V_MSG(wd.window_view, INVALID_WINDOW_ID, "Can't create a window view"); diff --git a/platform/macos/godot_main_macos.mm b/platform/macos/godot_main_macos.mm index 58263471b0..3959fb686c 100644 --- a/platform/macos/godot_main_macos.mm +++ b/platform/macos/godot_main_macos.mm @@ -65,7 +65,9 @@ int main(int argc, char **argv) { // We must override main when testing is enabled. TEST_MAIN_OVERRIDE - err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); + @autoreleasepool { + err = Main::setup(argv[0], argc - first_arg, &argv[first_arg]); + } if (err == ERR_HELP) { // Returned by --help and --version, so success. return 0; @@ -73,11 +75,17 @@ int main(int argc, char **argv) { return 255; } - if (Main::start()) { + bool ok; + @autoreleasepool { + ok = Main::start(); + } + if (ok) { os.run(); // It is actually the OS that decides how to run. } - Main::cleanup(); + @autoreleasepool { + Main::cleanup(); + } return os.get_exit_code(); } diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm index b8496d72fb..56542aff37 100644 --- a/platform/macos/os_macos.mm +++ b/platform/macos/os_macos.mm @@ -755,21 +755,25 @@ void OS_MacOS::run() { return; } - main_loop->initialize(); + @autoreleasepool { + main_loop->initialize(); + } bool quit = false; while (!quit) { - @try { - if (DisplayServer::get_singleton()) { - DisplayServer::get_singleton()->process_events(); // Get rid of pending events. - } - joypad_macos->process_joypads(); + @autoreleasepool { + @try { + if (DisplayServer::get_singleton()) { + DisplayServer::get_singleton()->process_events(); // Get rid of pending events. + } + joypad_macos->process_joypads(); - if (Main::iteration()) { - quit = true; + if (Main::iteration()) { + quit = true; + } + } @catch (NSException *exception) { + ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String)); } - } @catch (NSException *exception) { - ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String)); } } |