summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-03-11 14:18:56 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-14 15:27:41 +0100
commit48e6352d4c5f0cfd7341b029cc8151b968a7080d (patch)
treec67afb45ce76acb8b3cc328b81c201d1dc08354f /src/plugins/platforms/cocoa
parent8bbc1eaeb692368ae896072b24eb1a1b8d469cad (diff)
Cocoa: Fix crash when closing window from title bar
Some mouse event may result in the window being deleted so we need to take extra precaution when calling the super class' 'sendEvent:' method. Task-number: QTBUG-37287 Change-Id: Idf89ea177c78053bcdef52c54a197409e20bf38e Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm14
2 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 67cac41383..9128b05746 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -80,6 +80,7 @@ typedef NSWindow<QNSWindowProtocol> QCocoaNSWindow;
- (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow;
- (void)handleWindowEvent:(NSEvent *)theEvent;
+- (void) clearWindow;
@end
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index f1f88a13dd..c2a0c81b31 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -155,7 +155,14 @@ static bool isMouseEvent(NSEvent *ev)
}
}
+ // The call to -[NSWindow sendEvent] may result in the window being deleted
+ // (e.g., when closing the window by pressing the title bar close button).
+ [self retain];
[self.window superSendEvent:theEvent];
+ bool windowStillAlive = self.window != nil; // We need to read before releasing
+ [self release];
+ if (!windowStillAlive)
+ return;
if (!self.window.delegate)
return; // Already detached, pending NSAppKitDefined event
@@ -179,6 +186,11 @@ static bool isMouseEvent(NSEvent *ev)
self.window.delegate = nil;
}
+- (void)clearWindow
+{
+ _window = nil;
+}
+
- (void)dealloc
{
_window = nil;
@@ -259,6 +271,7 @@ static bool isMouseEvent(NSEvent *ev)
- (void)dealloc
{
+ [_helper clearWindow];
[_helper release];
_helper = nil;
[super dealloc];
@@ -319,6 +332,7 @@ static bool isMouseEvent(NSEvent *ev)
- (void)dealloc
{
+ [_helper clearWindow];
[_helper release];
_helper = nil;
[super dealloc];