From 7e34539e7587653b51ba702264635fb63219bad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 20 Nov 2023 14:45:58 +0100 Subject: [PATCH] macOS: Guard QCocoaWindow access when handling application activation change The platform window may in some cases be gone, without its NSWindow yet being deallocated, and if we receive an application activation event at this point we would try to dereference a null-pointer. Fixes: QTBUG-119219 Pick-to: 6.5 6.2 Change-Id: I72bb2482059d1a256e448705b132e4a8f22ec297 Reviewed-by: Volker Hilsheimer (cherry picked from commit 778acfe122baf5a65c1001e78050f333106a840d) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/cocoa/qnswindow.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 36666c87b78..74ba6f65ac9 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -107,9 +107,10 @@ NSWindow *qnswindow_cast(NSWindow *window) continue; if ([window conformsToProtocol:@protocol(QNSWindowProtocol)]) { - QCocoaWindow *cocoaWindow = static_cast(window).platformWindow; - window.level = notification.name == NSApplicationWillResignActiveNotification ? - NSNormalWindowLevel : cocoaWindow->windowLevel(cocoaWindow->window()->flags()); + if (QCocoaWindow *cocoaWindow = static_cast(window).platformWindow) { + window.level = notification.name == NSApplicationWillResignActiveNotification ? + NSNormalWindowLevel : cocoaWindow->windowLevel(cocoaWindow->window()->flags()); + } } // The documentation says that "when a window enters a new level, it’s ordered