Skip to content

Fix infinite recursion at startup when the output window was left in fullscreen - #634

Open
cccolo wants to merge 1 commit into
mapmapteam:devfrom
cccolo:fix/startup-recursion-output-fullscreen
Open

cccolo wants to merge 1 commit into
mapmapteam:devfrom
cccolo:fix/startup-recursion-output-fullscreen

Conversation

@cccolo

@cccolo cccolo commented Oct 28, 2026

Copy link
Copy Markdown

Problem

When the displayOutputWindow preference was saved as true (output window left in fullscreen on the previous run), MapMap never shows its window on the next start: it spins at ~90 % CPU and, on macOS, the console floods with Context leak detected, msgtracer returned -1.

MainWindow::window() lazily constructs the singleton and only stores the pointer after the constructor returns. readSettings(), called from inside the constructor, restores the output window in fullscreen; showing it repaints OutputGLCanvas, whose drawForeground() calls MainWindow::window(), which finds no instance yet and constructs a second MainWindow — recursively, forever. Each turn creates a new OpenGL context, hence the leak messages.

A sample of the hung process shows the loop (MainWindow::MainWindow() nested >1000 times):

mmp::OutputGLCanvas::drawForeground(QPainter*, QRectF const&)
  mmp::MainWindow::window()
    mmp::MainWindow::MainWindow()
      mmp::MainWindow::readSettings()
        QAction::setChecked(bool)
          mmp::OutputGLWindow::setFullScreen(bool)
            mmp::OutputGLWindow::_setFullScreen(bool)
              QWidget::showFullScreen()
                … QOpenGLWidget::event → QGraphicsView::paintEvent
                  mmp::OutputGLCanvas::drawForeground(QPainter*, QRectF const&)
                    mmp::MainWindow::window()
                      mmp::MainWindow::MainWindow()   ← again

Fix

Publish the singleton as the first thing the constructor does (_instance = this), so any code reached from inside construction gets this instance instead of building another one. The code is shared, so the same hang can happen on Windows and Linux.

How to reproduce / verify

macOS: defaults write com.artpluscode.MapMap displayOutputWindow -bool true, then launch — before this patch the app never appears; with it, it starts with the output window in fullscreen as expected. Tested on dev (cc29e94) with Qt 6.8.3 and 6.11.2 on Apple Silicon (macOS 15.5 and 26).

…fullscreen

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant