diff --git a/docs/changes.txt b/docs/changes.txt index 1a7c6ca584..30145ad3d6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -628,6 +628,7 @@ wxMSW: - Fix wxDV_ROW_LINES in horizontally scrolled wxDataViewCtrl. - Fix RegisterHotKey() with negative IDs (troelsk). - Fix event object type for wxEVT_SPINCTRL events. +- Fix bug if wxToolBar tool was deleted from its own handler (Artur Wieczorek). wxOSX: diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index ef53a2f487..ca8e9a6a51 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1398,6 +1398,17 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) bool allowLeftClick = OnLeftClick(id, toggled); + // Check if the tool hasn't been deleted in the event handler (notice that + // it's also possible that this tool was deleted and a new tool with the + // same ID was created, so we really need to check if the pointer to the + // tool with the given ID didn't change, not just that it's non null). + if ( FindById(id) != tool ) + { + // The rest of this event handler deals with updating the tool and must + // not be executed if the tool doesn't exist any more. + return true; + } + // Restore the unpressed state. Enabled/toggled state might have been // changed since so take care of it. if (tool->IsEnabled())