From 1c49a2e1bab998099e7590f73780ecb454ea4936 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Mon, 23 Jun 2014 20:00:42 +0000 Subject: [PATCH] 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 --- src/msw/menuitem.cpp | 7 +++++-- tests/menu/menu.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 1704892306..65ffdb6a16 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -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 } diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index 0ae436f27f..efc2f0a170 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -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); }