From 5d365b96b9a9d8585a0be5cc1c2376b7b2f27101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 16 Feb 2018 15:35:32 +0100 Subject: macOS: Warn the user when KVO-observing QCocoaNSWindow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We recreate the window of our QNSView in various situation such as changing the styleMask, which results in either a new QNSwindow or QNSpanel being set as the window of the view. KVO-observing the window property of the view will fail we then have a new window instance, and will crash when trying to remove the observer from the new window. Unfortunately catching the NSRangeException that happens when removing an observer from a 'switched' window is not possible, so the user is left with: Terminating app due to uncaught exception 'NSRangeException', reason: Cannot remove an observer for the key path "bar" from because it is not registered as an observer. Change-Id: Ib2adbb99f19303a054fb1eb65e959aecd32b1162 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoawindow.mm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 17ded6ce59..f9c676a5b0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1262,6 +1262,11 @@ void QCocoaWindow::recreateWindowIfNeeded() if ((isContentView() && !shouldBeContentView) || (recreateReason & PanelChanged)) { if (m_nsWindow) { qCDebug(lcQpaCocoaWindow) << "Getting rid of existing window" << m_nsWindow; + if (m_nsWindow.observationInfo) { + qCCritical(lcQpaCocoaWindow) << m_nsWindow << "has active key-value observers (KVO)!" + << "These will stop working now that the window is recreated, and will result in exceptions" + << "when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug."; + } [m_nsWindow closeAndRelease]; if (isContentView()) { // We explicitly disassociate m_view from the window's contentView, -- cgit v1.2.3