1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Don't hold a dangling pointer to a menu bar in CommandManager

This commit is contained in:
Paul Licameli
2018-10-20 12:50:22 -04:00
parent fefc3bf35d
commit 01875db4bd
3 changed files with 13 additions and 10 deletions

View File

@@ -597,17 +597,17 @@ wxMenuBar * CommandManager::CurrentMenuBar() const
}
///
/// Swap the last two menu bars in the list,
/// to make the previous menu bar 'current' again.
/// Typically used to switch back and forth
/// between adding to a hidden menu bar and
/// adding to one that is visible,
/// adding to one that is visible
///
void CommandManager::SwapMenuBars()
void CommandManager::PopMenuBar()
{
int l = mMenuBarList.size();
wxASSERT(l >= 2);
std::swap(mMenuBarList[l - 2], mMenuBarList[l - 1]);
auto iter = mMenuBarList.end();
if ( iter != mMenuBarList.begin() )
mMenuBarList.erase( --iter );
else
wxASSERT( false );
}

View File

@@ -40,7 +40,7 @@ struct MenuBarListEntry
{}
wxString name;
wxMenuBar *menubar; // This structure does not assume memory ownership!
wxWeakRef<wxMenuBar> menubar; // This structure does not assume memory ownership!
};
struct SubMenuListEntry
@@ -211,7 +211,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
const wxChar *accel,
CommandFlag flags);
void SwapMenuBars();
void PopMenuBar();
void SetOccultCommands( bool bOccult);