diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-03-22 13:40:38 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-03-22 14:00:11 (GMT) |
commit | 35ca28a576e7d71b789211bcad00fc4f907c6e91 (patch) | |
tree | 6bc0284aee95dc90952cb7908ec60dfb54e312f8 /src | |
parent | 6390248b11b3596d8c946c232e9b0d832dc42941 (diff) | |
download | Qt-35ca28a576e7d71b789211bcad00fc4f907c6e91.zip Qt-35ca28a576e7d71b789211bcad00fc4f907c6e91.tar.gz Qt-35ca28a576e7d71b789211bcad00fc4f907c6e91.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qeventdispatcher_mac.mm | 8 | ||||
-rw-r--r-- | 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<QWidget> widget; NSModalSession session; + void *nswindow; } QCocoaModalSessionInfo; #endif |