fixed a re-entrancy bug

This commit is contained in:
David Anderson 2006-02-09 12:04:35 +00:00
parent 52aa992a2f
commit a195a0af30

View File

@ -396,7 +396,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
return m_Text.c_str(); return m_Text.c_str();
} }
#define GETMENU(p) if (p >= (int)g_NewMenus.size() || p < 0 || !g_NewMenus[p]) { \ #define GETMENU(p) if (p >= (int)g_NewMenus.size() || p < 0 || !g_NewMenus[p] || g_NewMenus[p]->isDestroying) { \
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.size()); \ LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.size()); \
return 0; } \ return 0; } \
Menu *pMenu = g_NewMenus[p]; Menu *pMenu = g_NewMenus[p];
@ -733,15 +733,19 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params)
return 1; return 1;
} }
#define GETMENU_R(p) if (p >= (int)g_NewMenus.size() || p < 0 || !g_NewMenus[p]) { \
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.size()); \
return 0; } \
Menu *pMenu = g_NewMenus[p];
static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params) static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
{ {
GETMENU(params[1]); GETMENU_R(params[1]);
if (pMenu->isDestroying) if (pMenu->isDestroying)
return 0; //prevent infinite recursion return 0; //prevent infinite recursion
pMenu->isDestroying = true; pMenu->isDestroying = true;
g_NewMenus[params[1]] = NULL;
g_menucmds.removeMenuId(pMenu->menuId); g_menucmds.removeMenuId(pMenu->menuId);
CPlayer *player; CPlayer *player;
for (int i=1; i<=gpGlobals->maxClients; i++) for (int i=1; i<=gpGlobals->maxClients; i++)
@ -757,6 +761,7 @@ static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
player->menu = 0; player->menu = 0;
} }
} }
g_NewMenus[params[1]] = NULL;
delete pMenu; delete pMenu;
g_MenuFreeStack.push(params[1]); g_MenuFreeStack.push(params[1]);