diff --git a/lib/ui_platform_macos/src/lib.rs b/lib/ui_platform_macos/src/lib.rs index 5703ca1..97bb279 100644 --- a/lib/ui_platform_macos/src/lib.rs +++ b/lib/ui_platform_macos/src/lib.rs @@ -201,12 +201,13 @@ impl Drop for ObjcStrong { } struct NativeWindow { - window: ObjcStrong, - #[allow(dead_code)] - view: *mut AnyObject, - delegate: Option, - _metal_layer: Retained, + // Renderer/surface must drop before the AppKit objects whose raw handles it + // was created from. renderer: Option, + _metal_layer: Retained, + view: ObjcStrong, + delegate: Option, + window: ObjcStrong, } impl NativeWindow { @@ -219,7 +220,7 @@ impl NativeWindow { } fn view_object(&self) -> *mut AnyObject { - self.view + self.view.as_ptr() } fn set_title(&self, title: &str) { @@ -256,12 +257,12 @@ impl NativeWindow { } fn in_live_resize(&self) -> bool { - unsafe { objc2::msg_send![self.view, inLiveResize] } + unsafe { objc2::msg_send![self.view_object(), inLiveResize] } } fn display_if_needed(&self) { unsafe { - let _: () = objc2::msg_send![self.view, displayIfNeeded]; + let _: () = objc2::msg_send![self.view_object(), displayIfNeeded]; let _: () = objc2::msg_send![self.window_object(), displayIfNeeded]; } } @@ -1172,10 +1173,10 @@ fn drain_platform_commands(state: &Rc>) -> bool { unsafe { let _: () = objc2::msg_send![app, stop: std::ptr::null_mut::()]; } + set_command_wake_hook(None); if let Ok(mut slot) = run_loop_wake_handle().lock() { *slot = None; } - set_command_wake_hook(None); break; } } @@ -1588,7 +1589,7 @@ fn create_native_window(window: &MacosWindow, app: *mut AnyObject) -> Option Option()]; let _: () = objc2::msg_send![app, activateIgnoringOtherApps: true]; } - // NSWindow retains its content view. Drop our construction-time ownership so - // the window is the single owner from here. - view_owner.release_now(); - let metal_layer = configure_metal_surface_layer(view_obj)?; let scale_factor: f64 = unsafe { objc2::msg_send![window_obj, backingScaleFactor] }; @@ -1630,11 +1627,11 @@ fn create_native_window(window: &MacosWindow, app: *mut AnyObject) -> Option