If a few sub-menus are included each other, the BACK function works incorrectly, because gPrevMenuItemEntry remembers only the previous value, but the upper item menu is lost when you go to sub-sub-menu. In some cases if the gPrevMenuItemEntry is more than 2, the app crashes and gets stuck in main_assert(), when you back on the top level mainMenu, because there are only 3 items on the top level menu.
gPrevMenuItemEntry should be part of CUI_menu_s structure.
void CUI_menuActionBack(const int32_t _itemEntry)
{
if (NULL != gpCurrMenu->pUpper)
{
gpCurrMenu = gpCurrMenu->pUpper;
gCurrMenuItemEntry = gPrevMenuItemEntry;
}
}
Example of the fixed code:
void CUI_menuActionBack(const int32_t _itemEntry)
{
if (NULL != gpCurrMenu->pUpper)
{
gCurrMenuItemEntry = gpCurrMenu->gPrevMenuItemEntry;
gpCurrMenu = gpCurrMenu->pUpper;
}
}