From e278858f0728b9ac734d1d0ad6e68b6262dac534 Mon Sep 17 00:00:00 2001 From: msavara Date: Fri, 13 Feb 2026 19:46:31 +0100 Subject: [PATCH] fix(macOS): prevent crash on quit caused by double shutdown pat Fixes a macOS crash during app termination. App.Quit was closing MainWindow and then calling desktop.Shutdown(exitCode). Because the app runs with ShutdownMode.OnMainWindowClose, closing the main window already starts shutdown. Calling desktop.Shutdown again can re enter teardown while native AppKit and Avalonia dispatcher resources are already being finalized, which can end in SIGABRT on quit. The fix keeps a single shutdown path by calling only desktop.Shutdown(exitCode) in App.Quit, and it also adds a detailed inline comment that explains why this is required on macOS. --- src/App.axaml.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 2d9637530..9fc483686 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -387,7 +387,18 @@ public static void Quit(int exitCode) { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow?.Close(); + // IMPORTANT (especially on macOS): + // App shutdown must go through a single path only. + // + // The launcher runs with `ShutdownMode.OnMainWindowClose`, so calling + // `MainWindow.Close()` already starts the application shutdown sequence. + // If we then also call `desktop.Shutdown(...)`, we re-enter teardown + // from a second path while native resources (AppKit/Avalonia dispatcher) + // are already being finalized. + // + // In practice this has caused terminate/exit-time crashes on macOS + // (SIGABRT around NSApplication terminate + dispatcher cleanup). + // Therefore, `Quit()` must call only `desktop.Shutdown(exitCode)`. desktop.Shutdown(exitCode); } else