Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(macos): guard with_window_state against null app_box after windowWillClose

ManthanNimodiyaf6663a8002f1
diff --git a/apps/desktop/src-tauri/src/platform/macos/delegates.rs b/apps/desktop/src-tauri/src/platform/macos/delegates.rs
index 8c2c765e0..42fb8868f 100644
--- a/apps/desktop/src-tauri/src/platform/macos/delegates.rs
+++ b/apps/desktop/src-tauri/src/platform/macos/delegates.rs
@@ -88,10 +88,13 @@ pub fn setup<R: Runtime>(window: Window<R>, controls_inset: LogicalPosition<f64>
this: &Object,
func: F,
) {
- let ptr = unsafe {
- let x: *mut c_void = *this.get_ivar("app_box");
- &mut *(x as *mut WindowState<R>)
- };
+ let x: *mut c_void = unsafe { *this.get_ivar("app_box") };
+ // `app_box` is nulled out in `windowWillClose:`; ignore any late
+ // callbacks that arrive after that instead of dereferencing null.
+ if x.is_null() {
+ return;
+ }
+ let ptr = unsafe { &mut *(x as *mut WindowState<R>) };
func(ptr);
}