From 1b79d1cfe28a8fb77a3fb32438231d3670a268bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 27 Jan 2015 14:46:23 +0100 Subject: Fix crash-on-exit when embedding QNView The QWindow and QCocoaWindow may be deleted before the QNSView (which Cocoa keeps a reference to). Clear pointers to the Qt windows on QCocoaWindow destruction and add null-pointer check to QNView::isOpaque. Change-Id: I71764886c27bf1d14fb4e684c15e7c72e1c0a17c Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoawindow.mm | 8 ++++++++ src/plugins/platforms/cocoa/qnsview.h | 1 + src/plugins/platforms/cocoa/qnsview.mm | 8 ++++++++ 3 files changed, 17 insertions(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index c7a57d5776..bbf487c309 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -446,6 +446,14 @@ QCocoaWindow::~QCocoaWindow() name:nil object:m_nsWindow]; } + // The QNSView object may outlive the corresponding QCocoaWindow object, + // for example during app shutdown when the QNSView is embedded in a + // foregin NSView hiearchy. Clear the pointers to the QWindow/QCocoaWindow + // here to make sure QNSView does not dereference stale pointers. + if (m_qtView) { + [m_qtView clearQWindowPointers]; + } + foreach (QCocoaWindow *child, m_childWindows) { [m_nsWindow removeChildWindow:child->m_nsWindow]; child->m_parentCocoaWindow = 0; diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index 57e1e4e6bf..c3815ee60a 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -80,6 +80,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); - (id)init; - (id)initWithQWindow:(QWindow *)window platformWindow:(QCocoaWindow *) platformWindow; +- (void) clearQWindowPointers; #ifndef QT_NO_OPENGL - (void)setQCocoaGLContext:(QCocoaGLContext *)context; #endif diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index e2da8722a3..aa36a5d909 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -214,6 +214,12 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; return self; } +- (void) clearQWindowPointers +{ + m_window = 0; + m_platformWindow = 0; +} + #ifndef QT_NO_OPENGL - (void) setQCocoaGLContext:(QCocoaGLContext *)context { @@ -481,6 +487,8 @@ QT_WARNING_POP - (BOOL) isOpaque { + if (!m_platformWindow) + return true; return m_platformWindow->isOpaque(); } -- cgit v1.2.3