On Tue, May 12, 2026 at 06:15:56PM +0200, Pavel Sanda wrote:
>   The fix is straightforward: have the new LFUN_LYX_QUIT path call 
> writeSession() (and probably preserve the closing_ / lastOpened().clear() 
> semantics) before
>   tearing down work areas - e.g. call writeSession() on each view right 
> before closeBufferAll(), or move the session-write logic into 
> closeBufferAll() itself.

The fix is not that straightforward and gets uncomfortably long if we want to
preserve bunch of other stuff which we did before at the end of session before
(save ui settings, fullscreen toggle, original order of buffer closings, etc.)

Koji, could you test on the macos claude's theory why(*) the crash happened in
the first place, see the patch below - is it still crashing on mac this way?
Maybe we could avoid escalating the fix-of-fix-of-fix scenario...

Pavel

(*) close() is invoked synchronously from inside a QAction slot - Qt has to
tear down NSWindow / NSMenu state while the QAction-triggered invocation is
still on the stack. macOS Tahoe / Qt 6 might not tolerate that anymore.
QTimer::singleShot will defer to the next event-loop iteration.
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index f3070c525d..c74337ce47 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -103,9 +103,6 @@
 #include <QMenuBar>
 #include <QMimeData>
 #include <QObject>
-#if defined(Q_OS_MACOS) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
-#include <QOperatingSystemVersion>
-#endif
 #include <QPainter>
 #include <QPixmap>
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
@@ -1794,16 +1791,12 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		break;
 
 	case LFUN_LYX_QUIT:
-		if (current_view_) {
+		if (current_view_)
 			current_view_->message(from_utf8(N_("Exiting.")));
-			if (!current_view_->closeBufferAll()) {
-				current_view_->message(from_utf8(N_("Cancelled")));
-				break;
-			}
-		}
-		// quitting is triggered by the gui code
-		// (leaving the event loop).
-		QApplication::quit();
+		QTimer::singleShot(0, this, [this]() {
+			if (closeAllViews())
+				quit();
+		});
 		break;
 
 	case LFUN_SCREEN_FONT_UPDATE: {
diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h
index 727cd4ccec..a82447d831 100644
--- a/src/frontends/qt/GuiView.h
+++ b/src/frontends/qt/GuiView.h
@@ -165,8 +165,6 @@ public:
 	bool closeWorkArea(GuiWorkArea * wa);
 	/// closes the buffer
 	bool closeBuffer(Buffer & buf);
-	/// Close all document buffers.
-	bool closeBufferAll();
 
 	///
 	void openDocuments(std::string const & filename, int origin);
@@ -328,6 +326,8 @@ private:
 	void openChildDocument(std::string const & filename);
 	/// Close current document buffer.
 	bool closeBuffer();
+	/// Close all document buffers.
+	bool closeBufferAll();
 	///
 	TabWorkArea * addTabWorkArea();
 
-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to