From 228ecaad8b83b9ddb4f5bd8a398f75d5682af0a0 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 16 Sep 2014 16:05:46 +0000 Subject: [PATCH] backport, fixes #16564 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@77716 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/menu_osx.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 0b4b1fc296..57f722c5c0 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -46,6 +46,8 @@ wxMenuImpl::~wxMenuImpl() // the (popup) menu title has this special menuid static const int idMenuTitle = -3; +wxScopedPtr gs_emptyMenuBar; + // ============================================================================ // implementation // ============================================================================ @@ -73,7 +75,18 @@ void wxMenu::Init() wxMenu::~wxMenu() { - delete m_peer; +#if wxOSX_USE_CARBON + // when destroying the empty menu bar from the static scoped ptr + // the peer destructor removes an association from an already deleted + // hashmap leading to crashes. The guard avoids this, accepting some leaks... + static bool finalmenubar = false; + + if ( this == gs_emptyMenuBar.get() ) + finalmenubar = true; + + if ( !finalmenubar ) +#endif + delete m_peer; } WXHMENU wxMenu::GetHMenu() const @@ -585,8 +598,6 @@ bool wxMenuBar::s_macAutoWindowMenu = true ; WXHMENU wxMenuBar::s_macWindowMenuHandle = NULL ; -wxScopedPtr gs_emptyMenuBar; - const int firstMenuPos = 1; // to account for the 0th application menu on mac static wxMenu *CreateAppleMenu()