diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 3d4eb703c1..0f8f921aae 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -39,6 +39,7 @@ #include "wx/tooltip.h" #include "wx/spinctrl.h" #include "wx/geometry.h" +#include "wx/weakref.h" #if wxUSE_LISTCTRL #include "wx/listctrl.h" @@ -610,7 +611,7 @@ void wxWindowMac::SetFocus() void wxWindowMac::OSXSimulateFocusEvents() { - wxWindow* former = FindFocus() ; + wxWeakRef former = FindFocus() ; if ( former != NULL && former != this ) { { @@ -620,6 +621,9 @@ void wxWindowMac::OSXSimulateFocusEvents() former->HandleWindowEvent(event) ; } + // 'former' could have been destroyed by a wxEVT_KILL_FOCUS handler, + // so we must test it for non-NULL again + if ( former ) { wxFocusEvent event(wxEVT_SET_FOCUS, former->GetId()); event.SetEventObject(former);