Fix bug when a wxToolBar tool is deleted from its click handler
Deleting a tool from its own event handler resulted in at least in an assert
and could also lead to a crash as an already deallocated pointer was
dereferenced.
Fix this by checking if the tool with the same ID is still available after the
event handler finishes.
Closes #16762.
(this is a backport of faffaaae29
from master)
This commit is contained in:
committed by
Vadim Zeitlin
parent
234f081527
commit
f239eba7b0
@@ -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:
|
||||
|
||||
|
@@ -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())
|
||||
|
Reference in New Issue
Block a user