diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-10-25 15:43:30 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-11-02 15:22:39 +0000 |
commit | 3a92f7cf4f1abd7ad91bdfc7251b1f3e82bdf89f (patch) | |
tree | 21826cf775c4300f4af0d7a38805768833419a2e | |
parent | 17d51411132edef53e79dcbaf1046f06f79bed5d (diff) |
macOS: Retain NSWindow during event delivery
We have logic to deal with self.platformWindow and frame strut mouse
events which happens after delivering the event to the NSWindow, but
delivering it might dealloc the window, e.g. when closing it, so we
need to explicitly retain it for the duration of [QNSWindow sendEvent:]
Task-number: QTBUG-64023
Change-Id: I223fe3e3ac36a309da375522ba11f20f1ad6fc4f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-rw-r--r-- | src/plugins/platforms/cocoa/qnswindow.mm | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 799704a407..5213008bd4 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -185,6 +185,10 @@ static bool isMouseEvent(NSEvent *ev) if (!self.platformWindow) return; + // Prevent deallocation of this NSWindow during event delivery, as we + // have logic further below that depends on the window being alive. + [[self retain] autorelease]; + const char *eventType = object_getClassName(theEvent); if (QWindowSystemInterface::handleNativeEvent(self.platformWindow->window(), QByteArray::fromRawData(eventType, qstrlen(eventType)), theEvent, nullptr)) { @@ -221,6 +225,7 @@ static bool isMouseEvent(NSEvent *ev) #pragma clang diagnostic ignored "-Wobjc-missing-super-calls" - (void)dealloc { + qCDebug(lcQpaCocoaWindow) << "dealloc" << self; qt_objcDynamicSuper(); } #pragma clang diagnostic pop |