From 07d39abddd7f74eb9d2625cd26a73d62d694c7a5 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Fri, 9 Jun 2023 21:20:27 +0800 Subject: [PATCH] Fix panic when destroying window (#2773) * Fix crash when destroying window * Add a comment to draw_rect --------- Co-authored-by: Xiaopeng Li --- CHANGELOG.md | 1 + src/platform_impl/macos/view.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3fe89d..eeefa31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Web, scale factor and dark mode detection are now more robust. - On Web, fix the bfcache by not using the `beforeunload` event. - On Web, fix scale factor resize suggestion always overwriting the canvas size. +- On macOS, fix crash when dropping `Window`. # 0.28.6 diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 6513a3d3..314dc2cf 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -243,7 +243,10 @@ declare_class!( fn draw_rect(&mut self, rect: NSRect) { trace_scope!("drawRect:"); - AppState::handle_redraw(self.window_id()); + // It's a workaround for https://github.com/rust-windowing/winit/issues/2640, don't replace with `self.window_id()`. + if let Some(window) = self._ns_window.load() { + AppState::handle_redraw(WindowId(window.id())); + } #[allow(clippy::let_unit_value)] unsafe {