Don't crash in wxWindowMac::OSXSimulateFocusEvents().
The code didn't properly account for the possibility of wxEVT_KILL_FOCUS handler deleting the focused window (as happens e.g. in wxListCtrl inline edit controls). E.g. rapidly clicking wxEditableListBox buttons could trigger a crash here when sending wxEVT_SET_FOCUS to an already-deleted window. Use wxWeakRef<> to check if the window is still alive. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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<wxWindow> 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);
|
||||
|
Reference in New Issue
Block a user