diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2015-01-27 14:46:23 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-02-12 20:33:11 +0000 |
commit | 1b79d1cfe28a8fb77a3fb32438231d3670a268bc (patch) | |
tree | 54e540afad7e097a12ab00fd2bf362e9459c4996 /src/plugins | |
parent | 20598f53df8da349e5b0cf4c4bed7d0f4c9292b0 (diff) |
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 <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 8 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 8 |
3 files changed, 17 insertions, 0 deletions
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(); } |