From 214aebee08b6c10a794df576ffbff2d5c714027e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Nov 2013 12:01:20 +0000 Subject: [PATCH] Fix assert message when removing non-existent items from wxMenu. The assert complained about a bug in wxMenu code itself, but actually could be triggered by simply trying to remove a non-existent item from the menu. Fix this by checking for the item existence, and also removing it from the internal menu data structure, in wxMenuBase::Remove() and only dealing with the item itself in DoRemove(). Closes #3424. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75250 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/menucmn.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index e92a047041..713d314a9d 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -423,21 +423,20 @@ wxMenuItem *wxMenuBase::Remove(wxMenuItem *item) { wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Remove") ); - return DoRemove(item); -} - -wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) -{ wxMenuItemList::compatibility_iterator node = m_items.Find(item); // if we get here, the item is valid or one of Remove() functions is broken - wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); + wxCHECK_MSG( node, NULL, wxT("removing item not in the menu?") ); // we detach the item, but we do delete the list node (i.e. don't call // DetachNode() here!) m_items.Erase(node); - // item isn't attached to anything any more + return DoRemove(item); +} + +wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) +{ item->SetMenu(NULL); wxMenu *submenu = item->GetSubMenu(); if ( submenu )