summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-03-27 17:34:48 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-03-27 17:39:48 +0000
commit52767b8ee754f97abe42e9cdc3bcf69365a401fe (patch)
tree66e7ea012bdb78300398d083fb8269870d65df48 /src/plugins/platforms
parent0ec871dac839ea2b2661f1333dad39534e83f19d (diff)
macOS: Disassociate NSView from contentView when switching NSWindows
When a NSView is the contentView of a NSWindow, it still has a superview, in this case an NSThemeFrame, and the theme frame is the view that retains the view, not the contentView property of the window. Unfortunately, when a view is removed from the NSThemeFrame by means of [NSView removeFromSuperview], or indirectly via [NSView addSubview:], AppKit does not update the contentView property of the corresponding NSWindow. The result is that the NSView might be deallocated while the NSWindow still is around, with a stale contentView property. To work around this we explicitly disassociate the view from the NSWindow when we know that we are going to release the NSWindow. This will take care of both resetting the property to nil, and remove the view from the NSThemeFrame superview. Task-number: QTBUG-59734 Change-Id: I1111d492f52fe5bdf86bbae071421f6a8a7a38b8 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index cfe829905c..f6606745f1 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1613,6 +1613,13 @@ void QCocoaWindow::recreateWindowIfNeeded()
[m_nsWindow closeAndRelease];
if (isChildNSWindow())
[m_view.window.parentWindow removeChildWindow:m_view.window];
+ if (isContentView()) {
+ // We explicitly disassociate m_view from the window's contentView,
+ // as AppKit does not automatically do this in response to removing
+ // the view from the NSThemeFrame subview list, so we might end up
+ // with a NSWindow contentView pointing to a deallocated NSView.
+ m_view.window.contentView = nil;
+ }
m_nsWindow = 0;
}