From ebae7fc4264b393436450a6355df38eb97770f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A4=C3=A4tt=C3=A4=20Antti?= Date: Fri, 28 Jul 2017 13:45:29 +0300 Subject: [PATCH] Fix reset with qoffscreensurface destruction with multimonitor support The qoffscreensurface::setScreen crashes in create if application is closing. This happens in multimonitor setup when one of the screens is already destroyed and qoffscreensurface handles the screenDestroyed signal. In this case the QGuiApplication::primaryScreen returns non-null surface and selects the codepath that recreates the surface. The create function calls the qGuiApp->thread function, which crashes since the application instance has already been set to nullptr. Prevent this in qoffscreensurface by checking the application instance in the setScreen function. Task-number: QTBUG-62222 Change-Id: Ibb11a270c23a39e66009b45ab83dd7d47d5ccb1f Reviewed-by: Janne Koskinen Reviewed-by: Laszlo Agocs --- src/gui/kernel/qoffscreensurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp index 307bc5e62f..4d79db8ab2 100644 --- a/src/gui/kernel/qoffscreensurface.cpp +++ b/src/gui/kernel/qoffscreensurface.cpp @@ -317,7 +317,7 @@ void QOffscreenSurface::setScreen(QScreen *newScreen) { Q_D(QOffscreenSurface); if (!newScreen) - newScreen = QGuiApplication::primaryScreen(); + newScreen = QCoreApplication::instance() ? QGuiApplication::primaryScreen() : nullptr; if (newScreen != d->screen) { const bool wasCreated = d->platformOffscreenSurface != 0 || d->offscreenWindow != 0; if (wasCreated)