diff --git a/laf b/laf index f5baeae0e..0fc114e05 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit f5baeae0ecab0718f9a15499d0a8658317611a0f +Subproject commit 0fc114e05c23db1f6103b35fb79f3cd25b68ee63 diff --git a/src/app/app_menus.cpp b/src/app/app_menus.cpp index e4dd22afb..e72863e64 100644 --- a/src/app/app_menus.cpp +++ b/src/app/app_menus.cpp @@ -588,6 +588,10 @@ void AppMenus::removeMenuItemFromGroup(Pred pred) group.end = group.end->previousSibling(); item->parent()->removeChild(item); + if (auto appItem = dynamic_cast(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) diff --git a/src/app/ui/app_menuitem.cpp b/src/app/ui/app_menuitem.cpp index fc37da0c8..abe1ef6e7 100644 --- a/src/app/ui/app_menuitem.cpp +++ b/src/app/ui/app_menuitem.cpp @@ -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) { diff --git a/src/app/ui/app_menuitem.h b/src/app/ui/app_menuitem.h index bfcb7bdec..d62fa3a9c 100644 --- a/src/app/ui/app_menuitem.h +++ b/src/app/ui/app_menuitem.h @@ -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);