From d77260bc054d2ea2f0e0373a91156c3fd15d8d9f Mon Sep 17 00:00:00 2001 From: Jose Alvarez Date: Wed, 28 Oct 2026 13:43:22 -0300 Subject: [PATCH] Fix infinite recursion at startup when the output window was left in fullscreen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MainWindow::window() lazily constructs the singleton and only stores the pointer once the constructor returns. readSettings(), called from inside the constructor, restores the output window in fullscreen when the saved displayOutputWindow preference is true; showing it repaints OutputGLCanvas, whose drawForeground asks MainWindow::window(), which finds no instance yet and constructs a second MainWindow — forever. Each turn creates a new OpenGL context, so macOS floods the console with "Context leak detected, msgtracer returned -1" and the app never shows. Publish the singleton as the first thing the constructor does, so any code reached from inside construction gets this instance. --- src/gui/MainWindow.cpp | 11 +++++++---- src/gui/MainWindow.h | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index c8e79372..b9be40b5 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -39,8 +39,12 @@ namespace mmp { +MainWindow* MainWindow::_instance = nullptr; + MainWindow::MainWindow() { + _instance = this; + // Create model. #if QT_VERSION >= 0x050500 QMessageLogger(__FILE__, __LINE__, nullptr).info() << "Video support: " << @@ -3617,11 +3621,10 @@ QString MainWindow::locateMediaFile(const QString &uri, bool isImage) } MainWindow* MainWindow::window() { - static MainWindow* instance = nullptr; - if (!instance) { - instance = new MainWindow; + if (!_instance) { + new MainWindow; // sets _instance first thing } - return instance; + return _instance; } void MainWindow::updateCanvases() diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index fb17d9ca..80000770 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -363,6 +363,15 @@ public slots: static MainWindow* window(); +private: + // The singleton, published as soon as construction starts so that anything + // triggered from inside the constructor (e.g. restoring the output window in + // fullscreen repaints OutputGLCanvas, which asks for the main window) gets + // this instance instead of constructing a second one recursively. + static MainWindow* _instance; + +public: + // Returns a short version of filename. static QString strippedName(const QString &fullFileName);