From 42aa8aa8c2fb06cb98fb1c924976095b67a70a62 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 6 Feb 2014 17:34:03 +0100 Subject: [PATCH] Cocoa: Handle gracefully closing a window without event dispatcher Task-number: QTBUG-36696 Change-Id: I799eb351ee8ac1529cfbf009df3e7d57ec3a24ea Reviewed-by: Friedemann Kleint Reviewed-by: Simon Hausmann --- src/plugins/platforms/cocoa/qcocoawindow.mm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 8becfb1cc2..d13c6a8a3f 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -528,11 +528,13 @@ void QCocoaWindow::setVisible(bool visible) if (m_glContext) m_glContext->windowWasHidden(); QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast(QGuiApplication::instance()->eventDispatcher()); - Q_ASSERT(cocoaEventDispatcher != 0); - QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast(QObjectPrivate::get(cocoaEventDispatcher)); + QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = 0; + if (cocoaEventDispatcher) + cocoaEventDispatcherPrivate = static_cast(QObjectPrivate::get(cocoaEventDispatcher)); if (m_nsWindow) { if (m_hasModalSession) { - cocoaEventDispatcherPrivate->endModalSession(window()); + if (cocoaEventDispatcherPrivate) + cocoaEventDispatcherPrivate->endModalSession(window()); m_hasModalSession = false; } else { if ([m_nsWindow isSheet]) @@ -540,7 +542,8 @@ void QCocoaWindow::setVisible(bool visible) } hide(); - if (m_nsWindow == [NSApp keyWindow] && !cocoaEventDispatcherPrivate->currentModalSession()) { + if (m_nsWindow == [NSApp keyWindow] + && !(cocoaEventDispatcherPrivate && cocoaEventDispatcherPrivate->currentModalSession())) { // Probably because we call runModalSession: outside [NSApp run] in QCocoaEventDispatcher // (e.g., when show()-ing a modal QDialog instead of exec()-ing it), it can happen that // the current NSWindow is still key after being ordered out. Then, after checking we