From 4c6631c7640c4b8fce2979e8f6909e1e008ad229 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Sun, 15 Jan 2023 17:04:57 +0100 Subject: [PATCH] mac: retain the NSWindow to ensure that the call to retrieving the backing scale factor in set_buffer works --- src/cg.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cg.rs b/src/cg.rs index 1309a43..54573fe 100644 --- a/src/cg.rs +++ b/src/cg.rs @@ -22,6 +22,7 @@ pub struct CGImpl { impl CGImpl { pub unsafe fn new(handle: AppKitWindowHandle) -> Result { let window = handle.ns_window as id; + let window: id = msg_send![window, retain]; let view = handle.ns_view as id; let layer = CALayer::new(); unsafe { @@ -71,3 +72,11 @@ impl CGImpl { transaction::commit(); } } + +impl Drop for CGImpl { + fn drop(&mut self) { + unsafe { + let _: () = msg_send![self.window, release]; + } + } +}