Avoid crashing if interface file is not at the good version

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-20 17:43:50 +01:00
parent 332a2b5a74
commit db3271289d

View file

@ -203,11 +203,12 @@ void CItemGroupManager::linkInterface()
CGroupSubMenu *pMenu = pRootMenu->getRootMenu(); CGroupSubMenu *pMenu = pRootMenu->getRootMenu();
//get item subgroup //get item subgroup
CGroupMenu *pGroupMenu = dynamic_cast<CGroupMenu*>(pWM->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu")); CGroupMenu *pGroupMenu = dynamic_cast<CGroupMenu*>(pWM->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu"));
CGroupSubMenu *pGroupSubMenu = pGroupMenu->getRootMenu(); CGroupSubMenu *pGroupSubMenu = NULL;
if(pMenu && pGroupSubMenu) if (pGroupMenu) pGroupSubMenu = pGroupMenu->getRootMenu();
if (pMenu && pGroupSubMenu)
pMenu->setSubMenu(pMenu->getNumLine() - 1, pGroupSubMenu); pMenu->setSubMenu(pMenu->getNumLine() - 1, pGroupSubMenu);
else else
nlwarning("Couldn't link group action to group menu, interface isn't initialize yet ?"); nlwarning("Couldn't link group submenu to item_menu_in_bag, check your widgets.xml file");
} }
void CItemGroupManager::uninit() void CItemGroupManager::uninit()
@ -222,9 +223,10 @@ void CItemGroupManager::unlinkInterface()
// We need to unlink our menu to avoid crash on interface release // We need to unlink our menu to avoid crash on interface release
CWidgetManager* pWM = CWidgetManager::getInstance(); CWidgetManager* pWM = CWidgetManager::getInstance();
CGroupMenu *pGroupMenu = dynamic_cast<CGroupMenu*>(pWM->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu")); CGroupMenu *pGroupMenu = dynamic_cast<CGroupMenu*>(pWM->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu"));
CGroupSubMenu *pGroupSubMenu = pGroupMenu->getRootMenu(); CGroupSubMenu *pGroupSubMenu = NULL;
pGroupMenu->reset(); if (pGroupMenu) pGroupSubMenu = pGroupMenu->getRootMenu();
pGroupMenu->delGroup(pGroupSubMenu, true); if (pGroupMenu) pGroupMenu->reset();
if (pGroupMenu && pGroupSubMenu) pGroupMenu->delGroup(pGroupSubMenu, true);
} }
// Inspired from macro parsing // Inspired from macro parsing