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>
This commit is contained in:
parent
8bbc1eaeb6
commit
48e6352d4c
@ -80,6 +80,7 @@ typedef NSWindow<QNSWindowProtocol> QCocoaNSWindow;
|
||||
|
||||
- (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow;
|
||||
- (void)handleWindowEvent:(NSEvent *)theEvent;
|
||||
- (void) clearWindow;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user