From 1b3cba17e8dcc541a7602073609a34b0ff599a9c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 19 May 2014 16:58:18 +0000 Subject: [PATCH] guarding against deleted 'self' during the mouse handler, setting peer ptr to NULL during destruction git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76579 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/window.mm | 8 ++++++-- src/osx/window_osx.cpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index c6f0756b4c..e5d1183cb5 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1302,8 +1302,12 @@ void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd) superimpl(slf, (SEL)_cmd, event); // super of built-ins keeps the mouse up, as wx expects this event, we have to synthesize it - // only trigger if at this moment the mouse is already up - if ( [ event type] == NSLeftMouseDown && !wxGetMouseState().LeftIsDown() ) + // only trigger if at this moment the mouse is already up, and the control is still existing after the event has + // been handled (we do this by looking up the native NSView's peer from the hash map, that way we are sure the info + // is current - even when the instance memory of ourselves may have been freed ... + + wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( slf ); + if ( [ event type] == NSLeftMouseDown && !wxGetMouseState().LeftIsDown() && impl != NULL ) { wxMouseEvent wxevent(wxEVT_LEFT_DOWN); SetupMouseEvent(wxevent , event) ; diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 9c2f8284ff..2f44b86799 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -2875,6 +2875,7 @@ wxWidgetImpl::wxWidgetImpl() wxWidgetImpl::~wxWidgetImpl() { + m_wxPeer = NULL; } void wxWidgetImpl::Init()