Merge pull request #87836 from stuartcarnie/autoreleasepool

macOS: Use autorelease pools
This commit is contained in:
Rémi Verschelde 2024-02-02 12:04:50 +01:00
commit 92ff4f7877
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 26 additions and 13 deletions

View file

@ -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");

View file

@ -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();
}

View file

@ -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));
}
}