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.6 6.5 6.2
Change-Id: I72bb2482059d1a256e448705b132e4a8f22ec297
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Tor Arne Vestbø 2023-11-20 14:45:58 +01:00
parent 6335685a1b
commit 778acfe122
1 changed files with 4 additions and 3 deletions

View File

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