mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
[osx] Fix some leaks regenerating native menus
This commit is contained in:
parent
7ad1b7b965
commit
bb07d25025
2
laf
2
laf
@ -1 +1 @@
|
||||
Subproject commit f5baeae0ecab0718f9a15499d0a8658317611a0f
|
||||
Subproject commit 0fc114e05c23db1f6103b35fb79f3cd25b68ee63
|
@ -588,6 +588,10 @@ void AppMenus::removeMenuItemFromGroup(Pred pred)
|
||||
group.end = group.end->previousSibling();
|
||||
|
||||
item->parent()->removeChild(item);
|
||||
if (auto appItem = dynamic_cast<AppMenuItem*>(item)) {
|
||||
if (appItem)
|
||||
appItem->disposeNative();
|
||||
}
|
||||
item->deferDelete();
|
||||
|
||||
it = group.items.erase(it);
|
||||
@ -809,8 +813,7 @@ void AppMenus::createNativeMenus()
|
||||
if (!menus) // This platform doesn't support native menu items
|
||||
return;
|
||||
|
||||
if (m_osMenu)
|
||||
m_osMenu->dispose();
|
||||
os::Menu* oldOSMenu = m_osMenu;
|
||||
m_osMenu = menus->createMenu();
|
||||
|
||||
#ifdef __APPLE__ // Create default macOS app menus (App ... Window)
|
||||
@ -896,6 +899,8 @@ void AppMenus::createNativeMenus()
|
||||
#endif
|
||||
|
||||
menus->setAppMenu(m_osMenu);
|
||||
if (oldOSMenu)
|
||||
oldOSMenu->dispose();
|
||||
}
|
||||
|
||||
void AppMenus::createNativeSubmenus(os::Menu* osMenu, const ui::Menu* uiMenu)
|
||||
|
@ -50,8 +50,11 @@ AppMenuItem::AppMenuItem(const std::string& text,
|
||||
AppMenuItem::~AppMenuItem()
|
||||
{
|
||||
if (m_native) {
|
||||
if (m_native->menuItem)
|
||||
m_native->menuItem->dispose();
|
||||
// Do not call disposeNative(), the native handle will be disposed
|
||||
// when the main menu (app menu) is disposed.
|
||||
|
||||
// TODO improve handling of these kind of pointer from laf-os library
|
||||
|
||||
delete m_native;
|
||||
}
|
||||
}
|
||||
@ -67,12 +70,23 @@ void AppMenuItem::setNative(const Native& native)
|
||||
if (!m_native)
|
||||
m_native = new Native(native);
|
||||
else {
|
||||
if (m_native->menuItem)
|
||||
m_native->menuItem->dispose();
|
||||
// Do not call disposeNative(), the native handle will be disposed
|
||||
// when the main menu (app menu) is disposed.
|
||||
|
||||
*m_native = native;
|
||||
}
|
||||
}
|
||||
|
||||
void AppMenuItem::disposeNative()
|
||||
{
|
||||
#if 0 // TODO fix this and the whole handling of native menu items from laf-os
|
||||
if (m_native->menuItem) {
|
||||
m_native->menuItem->dispose();
|
||||
m_native->menuItem = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void AppMenuItem::syncNativeMenuItemKeyShortcut()
|
||||
{
|
||||
if (m_native) {
|
||||
|
@ -49,6 +49,7 @@ namespace app {
|
||||
|
||||
Native* native() { return m_native; }
|
||||
void setNative(const Native& native);
|
||||
void disposeNative();
|
||||
void syncNativeMenuItemKeyShortcut();
|
||||
|
||||
static void setContextParams(const Params& params);
|
||||
|
Loading…
Reference in New Issue
Block a user