summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-08-06 16:16:49 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-08-07 12:07:03 +0000
commitcaa68b9c538aa30ec6fc3feed2847fbe53d904b6 (patch)
tree3b562634546c6642f593c7c69c2a190a6d5fd597
parent25e0e6273d9e9ba20147aa3c7479830fd12a254d (diff)
macOS: Fix crash when re-using backingstore for re-created QWindow
The observer we add for the NSWindow of the backingstore window will not be valid once that window is destroyed, but we may get last minute notifications for it still, in which case our platform window is gone. This patch fixes the immediate crash, but reveals a more fundamental problem of assuming the platform window that's alive during construction is the one that will always be used with the backingstore. This is not the case when for example QtWidgets opens a combo box, and reuses the backingstore for the widget each time the combobox popup is shown. Fixes: QTBUG-85915 Change-Id: Ia66a45d003882602ac29476aabf2d58b0ac33c1e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit abb985a4032a337581aa885e1ac547287244b695) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index 6aa0c0182f..6ea6714649 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -357,6 +357,14 @@ QCALayerBackingStore::QCALayerBackingStore(QWindow *window)
NSView *view = static_cast<QCocoaWindow *>(window->handle())->view();
m_backingPropertiesObserver = QMacNotificationObserver(view.window,
NSWindowDidChangeBackingPropertiesNotification, [this]() {
+ if (!this->window()->handle()) {
+ // The platform window has been destroyed, but the backingstore
+ // is still alive, as that's tied to a QWindow. The original
+ // NSWindow we were observing is also likely gone. FIXME:
+ // We should listen for surface events from the QWindow and
+ // remove and re-attach our observer based on those.
+ return;
+ }
qCDebug(lcQpaBackingStore) << "Backing properties for"
<< this->window() << "did change";
backingPropertiesChanged();