summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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];