From 35ca28a576e7d71b789211bcad00fc4f907c6e91 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 22 Mar 2010 14:40:38 +0100 Subject: Cocoa: fix eventdispatcher crash, found by macgui autotest In some cases, we end up deleting a widget before we get to end the modal session that might be attached to it. And that will cause a crash. This patch retains/releases the underlying NSWindow, so we always have a valid reference as long as the modal session is alive. Reviewed-by: msorvig --- src/gui/kernel/qeventdispatcher_mac.mm | 8 ++++++-- src/gui/kernel/qeventdispatcher_mac_p.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index afea3ec..62e1e81 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -829,6 +829,8 @@ NSModalSession QEventDispatcherMacPrivate::currentModalSession() ensureNSAppInitialized(); QBoolBlocker block1(blockSendPostedEvents, true); + info.nswindow = window; + [(NSWindow*) info.nswindow retain]; info.session = [NSApp beginModalSessionForWindow:window]; } currentModalSessionCached = info.session; @@ -903,8 +905,10 @@ void QEventDispatcherMacPrivate::cleanupModalSessions() } cocoaModalSessionStack.remove(i); currentModalSessionCached = 0; - if (info.session) + if (info.session) { [NSApp endModalSession:info.session]; + [(NSWindow *)info.nswindow release]; + } } updateChildrenWorksWhenModal(); @@ -920,7 +924,7 @@ void QEventDispatcherMacPrivate::beginModalSession(QWidget *widget) // currentModalSession). A QCocoaModalSessionInfo is considered pending to be stopped if // the widget pointer is zero, and the session pointer is non-zero (it will be fully // stopped in cleanupModalSessions()). - QCocoaModalSessionInfo info = {widget, 0}; + QCocoaModalSessionInfo info = {widget, 0, 0}; cocoaModalSessionStack.push(info); updateChildrenWorksWhenModal(); currentModalSessionCached = 0; diff --git a/src/gui/kernel/qeventdispatcher_mac_p.h b/src/gui/kernel/qeventdispatcher_mac_p.h index e932532..8ac7c65 100644 --- a/src/gui/kernel/qeventdispatcher_mac_p.h +++ b/src/gui/kernel/qeventdispatcher_mac_p.h @@ -100,6 +100,7 @@ typedef struct _NSModalSession *NSModalSession; typedef struct _QCocoaModalSessionInfo { QPointer widget; NSModalSession session; + void *nswindow; } QCocoaModalSessionInfo; #endif -- cgit v0.12