Fix exception while reinserting menu item.
After removing an item from a menu that item's parent menu is set to NULL and can't be used any longer to insert the item again. Fix by remembering the parent menu before removing the item from it. Regression since r76251 (this commit is a partial revert of that commit). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76755 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -780,8 +780,11 @@ void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
||||
{
|
||||
wxCHECK_RET( item == this, wxS("Non unique menu item ID?") );
|
||||
|
||||
m_parentMenu->Remove(this);
|
||||
m_parentMenu->Insert(pos, this);
|
||||
// Use a copied value of m_parentMenu because it is
|
||||
// nullified by Remove.
|
||||
wxMenu *menu = m_parentMenu;
|
||||
menu->Remove(this);
|
||||
menu->Insert(pos, this);
|
||||
}
|
||||
//else: the item hasn't been inserted into the parent menu yet
|
||||
}
|
||||
|
@@ -420,6 +420,12 @@ void MenuTestCase::ChangeBitmap()
|
||||
// again etc...
|
||||
item->SetBitmap( wxBitmap(1, 1) );
|
||||
|
||||
|
||||
// Force owner drawn usage by having a bitmap that's wider than the
|
||||
// standard size. This results in rearranging the parent menu which
|
||||
// hasn't always worked properly and lead to a null pointer exception.
|
||||
item->SetBitmap( wxBitmap(512, 1) );
|
||||
|
||||
wxDELETE(menu);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user