Skip to content

Fix crash on quit while the Open With menu is being populated - #876

Merged
jurplel merged 2 commits into
jurplel:mainfrom
AndyOrbis:fix-quit-crash-openwith
Nov 4, 2026
Merged

jurplel merged 2 commits into
jurplel:mainfrom
AndyOrbis:fix-quit-crash-openwith

Conversation

@AndyOrbis

@AndyOrbis AndyOrbis commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #864.

Cause

requestPopulateOpenWithMenu() runs OpenWith::getOpenWithItems() on the global thread pool, and that code creates QPixmaps. If the user quits while this task is still running, ~QCoreApplication runs first and only then waits for the pool. The worker then calls qt_pixmap_thread_test(), which hits qFatal("QPixmap: Must construct a QGuiApplication before a QPixmap") → SIGABRT.

Change

  • main(): wait for QThreadPool::globalInstance() while the application object still exists.
  • The worker lambda captures the file path by value instead of this by reference, so the task never touches a window that may already be closed.

Testing

Tested on macOS 27.0.1 (Apple Silicon). The build was the 7.1 tag plus this change and b6ca96c (16/32 px menu icons), against Qt 6.8.3, the version the release bundle ships. The changed code is identical on main. I did not build main locally.

Scenario, 10 runs each 7.1 release Patched
Open an image, quit 0.6–1.5 s later via the quit Apple Event (osascript) 8 crashes 0 crashes
Same, then open another image 0.5 s after quitting — 0 lost

I did not check the contents of the Open With menu by eye; the code that builds it is unchanged.

b6ca96c matters here. Without it the Open With task renders every icon size up to 1024 px and takes up to ~3 s. Quitting then waits that long, and macOS delivers a file opened during that time to the exiting instance, so the file is lost.

requestPopulateOpenWithMenu() builds the menu on the global thread pool,
and OpenWith::getOpenWithItems() creates QPixmaps there. Quitting while
that task is still running destroys the QApplication first; the worker
then hits qt_pixmap_thread_test() -> qFatal() and the app aborts.

- main(): wait for the global thread pool before the application object
  is destroyed.
- ~MainWindow(): wait for the Open With future, since the task belongs to
  this window.
- Capture the file path by value instead of capturing `this` by
  reference in the worker lambda.

Fixes jurplel#864
The task captures the file path by value and no longer touches the
window, so ~MainWindow() doesn't need to wait for it. Waiting froze the
GUI for up to a few seconds when a window was closed right after
opening an image. main() still waits for the thread pool on quit.

@jurplel jurplel left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thank you for this fix

@jurplel
jurplel merged commit b8b993a into jurplel:main Nov 4, 2026
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.

macOS: SIGABRT when quitting shortly after opening an image

2 participants