From c1d293296cf1dc9e33aa890b515dcf65cbfb9b09 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 11 Oct 2026 12:38:19 +0200 Subject: [PATCH] macOS: end the process in on_exit so quitting doesn't crash (#117) AccessKit's macOS adapter subclasses the window's content view and restores its class when the window is torn down; AppKit's Touch Bar support observes that view via KVO, so the next display cycle throws in -[_NSTouchBarFinderObservation invalidate] and the quit ends in a crash report. On macOS, on_exit now exits right after saving the preferences, before eframe drops the window (what eframe itself does without run_and_return). Same fix as storytold/vectorcraft#670. Co-Authored-By: Claude Opus 5.5 --- apps/gridcraft/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/gridcraft/src/main.rs b/apps/gridcraft/src/main.rs index 3c73a95..b8d6fa9 100644 --- a/apps/gridcraft/src/main.rs +++ b/apps/gridcraft/src/main.rs @@ -51,6 +51,16 @@ impl eframe::App for App { } fn on_exit(&mut self) { save_prefs(&self.0); + // macOS (#117): end the process here, before eframe tears the window down. AccessKit's + // macOS adapter subclasses the window's content view and restores its class on teardown; + // AppKit's Touch Bar support observes that view (KVO), so in the next display cycle + // `-[_NSTouchBarFinderObservation invalidate]` throws "not registered" and the quit ends + // in a crash report. eframe calls `on_exit` on every way of quitting (Quit/⌘Q, the Dock, + // the close button, `app.quit`), and nothing after it is needed: the preferences are + // saved and the log file is unbuffered. eframe does the same when it doesn't + // run-and-return. `on_exit` only runs once the app exists, never on a failed start. + #[cfg(target_os = "macos")] + std::process::exit(0); } }