From 3de6d1eb17fd32ea54f5a08718b76bc0ac7067d2 Mon Sep 17 00:00:00 2001 From: tommash Date: Fri, 15 Dec 2017 15:01:26 +0100 Subject: [PATCH 1/2] MouseEvent crash fix on wxWindow Destroy If the event handler destroys the wxWindow, then the subsequent call to SetupCursor(event) will miserably fail . Moved setting the cursor before the event is handled. --- src/osx/cocoa/window.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index b218573f9e..8b3bf8e68e 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3579,11 +3579,11 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) { + (void)SetupCursor(event); + wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent(wxevent , event) ; bool result = GetWXPeer()->HandleWindowEvent(wxevent); - - (void)SetupCursor(event); return result; } From df2f0321fb1f7ba9033a3fb6174e74562cd4e0fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 15 Dec 2017 16:52:41 +0100 Subject: [PATCH 2/2] Some simplification and tidying up of the previous commit Explain why the order here is important. Also get rid of now unnecessary temporary variable. --- src/osx/cocoa/window.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 8b3bf8e68e..ffe70b4429 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3579,13 +3579,13 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event) { + // Call this before handling the event in case the event handler destroys + // this window. (void)SetupCursor(event); wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent(wxevent , event) ; - bool result = GetWXPeer()->HandleWindowEvent(wxevent); - - return result; + return GetWXPeer()->HandleWindowEvent(wxevent); } void wxWidgetCocoaImpl::DoNotifyFocusSet()