Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.1
Description
Summary:
An application compiled with Qt 5.12.1 occasionally crashes when unplugging the external monitors from a MacBookPro running on macOS 10.14.3.
Steps to reproduce:
- I have a MacBookPro with a Thunderbolt Dock and 2 screens connected to the Dock.
- Run an application compiled with Qt 5.12.1
- Detach the Thunderbolt Dock from the MacBookPro
Result: The application sometimes crashes.
More information:
The crash occurs in QCocoaWindow::windowDidChangeScreen():
void QCocoaWindow::windowDidChangeScreen() { if (!window()) return; const bool wasRunningDisplayLink = static_cast<QCocoaScreen *>(screen())->isRunningDisplayLink();
Note the call to the function screen() which can return a nullptr:
/*! Returns the platform screen handle corresponding to this platform window, or null if the window is not associated with a screen. */ QPlatformScreen *QPlatformWindow::screen() const { QScreen *scr = window()->screen(); return scr ? scr->handle() : nullptr; }
Suggested fix:
The QCocoaWindow::windowDidChangeScreen() function should check if screen() returns a nullptr pointer before using it. One possible fix would be to modify QCocoaWindow::windowDidChangeScreen() as follow:
void QCocoaWindow::windowDidChangeScreen() { if (!window()) return; if (!screen()) return; const bool wasRunningDisplayLink = static_cast<QCocoaScreen *>(screen())->isRunningDisplayLink();