Use objc's autoreleasepool instead of manually with NSAutoreleasePool (#1936)

Ensures the pools are released even if we panic
This commit is contained in:
Mads Marquart 2021-05-27 17:38:41 +02:00 committed by GitHub
parent 657b4fd59e
commit 982ad46c83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 58 deletions

View file

@ -15,11 +15,12 @@ use std::{
use cocoa::{
appkit::{NSApp, NSApplication, NSWindow},
base::{id, nil},
foundation::{NSAutoreleasePool, NSSize},
foundation::NSSize,
};
use objc::{
rc::autoreleasepool,
runtime::{Object, YES},
};
use objc::runtime::YES;
use objc::runtime::Object;
use crate::{
dpi::LogicalSize,
@ -403,16 +404,16 @@ impl AppState {
};
let dialog_is_closing = HANDLER.dialog_is_closing.load(Ordering::SeqCst);
let pool = NSAutoreleasePool::new(nil);
if !INTERRUPT_EVENT_LOOP_EXIT.load(Ordering::SeqCst)
&& !dialog_open
&& !dialog_is_closing
{
let () = msg_send![app, stop: nil];
// To stop event loop immediately, we need to post some event here.
post_dummy_event(app);
}
pool.drain();
autoreleasepool(|| {
if !INTERRUPT_EVENT_LOOP_EXIT.load(Ordering::SeqCst)
&& !dialog_open
&& !dialog_is_closing
{
let () = msg_send![app, stop: nil];
// To stop event loop immediately, we need to post some event here.
post_dummy_event(app);
}
});
if window_count > 0 {
let window: id = msg_send![windows, objectAtIndex:0];