From 665e09bb3e4443a0fd31b1c06437d525672cabf8 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:43:20 +0100 Subject: [PATCH] Fix segfault when dropping MacWindow (cherry-pick #9267) (#9269) Cherry-picked Fix segfault when dropping MacWindow (#9267) This avoids calling `window.setDelegate(nil)` when the window was already closed. Release Notes: - Fixed a segfault that could show up when closing windows. Co-authored-by: Antonio Co-authored-by: Thorsten Ball Co-authored-by: Antonio --- crates/gpui/src/platform/mac/window.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 8e48cbef306186c237696bc7b17e9154ef1bbdc0..a144f3a3ef646375c7be28927762526241af650d 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -738,10 +738,11 @@ impl Drop for MacWindow { this.renderer.destroy(); let window = this.native_window; this.display_link.take(); - unsafe { - this.native_window.setDelegate_(nil); - } if !this.native_window_was_closed { + unsafe { + this.native_window.setDelegate_(nil); + } + this.executor .spawn(async move { unsafe {