summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-08-06 16:16:49 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-08-07 12:01:22 +0200
commitabb985a4032a337581aa885e1ac547287244b695 (patch)
treed51d54b2336df54ba5d7b19aa4e4197c596aaf35 /src/plugins/platforms/cocoa
parent5735a14c2b16a247e4bd1c3b6a33203a86a8ed8a (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 Pick-to: 5.15 Pick-to: 5.12 Change-Id: Ia66a45d003882602ac29476aabf2d58b0ac33c1e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-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 26cab9aa58..aedce10c1f 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -347,6 +347,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();