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 <volker.hilsheimer@qt.io>
(cherry picked from commit 778acfe122baf5a65c1001e78050f333106a840d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-11-20 14:45:58 +01:00 committed by Qt Cherry-pick Bot
parent d1e7e4b02c
commit 7e34539e75

View File

@ -107,9 +107,10 @@ NSWindow<QNSWindowProtocol> *qnswindow_cast(NSWindow *window)
continue; continue;
if ([window conformsToProtocol:@protocol(QNSWindowProtocol)]) { if ([window conformsToProtocol:@protocol(QNSWindowProtocol)]) {
QCocoaWindow *cocoaWindow = static_cast<QCocoaNSWindow *>(window).platformWindow; if (QCocoaWindow *cocoaWindow = static_cast<QCocoaNSWindow *>(window).platformWindow) {
window.level = notification.name == NSApplicationWillResignActiveNotification ? window.level = notification.name == NSApplicationWillResignActiveNotification ?
NSNormalWindowLevel : cocoaWindow->windowLevel(cocoaWindow->window()->flags()); NSNormalWindowLevel : cocoaWindow->windowLevel(cocoaWindow->window()->flags());
}
} }
// The documentation says that "when a window enters a new level, its ordered // The documentation says that "when a window enters a new level, its ordered