From abb985a4032a337581aa885e1ac547287244b695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 6 Aug 2020 16:16:49 +0200 Subject: 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 --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/plugins/platforms/cocoa') 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(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(); -- cgit v1.2.3