From 8524d29ce8aa16c65abd8eb6688ce24b710fe356 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 21 Apr 2020 12:28:07 +0200 Subject: Prevent asserts in certain QWindow re-creation cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends 402efef57bb6a04ad778d3139100becc2cba31eb. The original patch has a problem, namely that it directly calls QPlatformWindow::requestUpdate() instead of going through QWindow::requestUpdate(). As there is a chance that an update gets scheduled between the creation of the QPlatformWindow and this extra, optional invocation of requestUpdate() at the end of QWindow::create(), this becomes quite unsafe because QPlatformWindow, unlike QWindow, is not graceful: it will just assert if there is a pending update still. Solve the whole thing by storing the updateRequestPending flag of QWindowPrivate, then resetting it, and then going through the safe, public QWindow::requestUpdate() when our copy of the flag says so. Task-number: QTBUG-81400 Task-number: QTBUG-70957 Pick-to: 5.15 Change-Id: I99aedfae3928b75301b46a4666c169e657ff8079 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qwindow.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 702c055fbbd..fd89e479b89 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -515,6 +515,11 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle) if (platformWindow) return; + // avoid losing update requests when re-creating + const bool needsUpdate = updateRequestPending; + // the platformWindow, if there was one, is now gone, so make this flag reflect reality now + updateRequestPending = false; + if (q->parent()) q->parent()->create(); @@ -553,8 +558,8 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle) QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated); QGuiApplication::sendEvent(q, &e); - if (updateRequestPending) - platformWindow->requestUpdate(); + if (needsUpdate) + q->requestUpdate(); } void QWindowPrivate::clearFocusObject() -- cgit v1.2.3