Fix crash when deleting a Menu handle during callbacks (#2536)

* Root menu Handles during callbacks

* Delete unused AutoHandleRooter struct

* Fix crash when a vote is cancelled from its start callback

* menus: root vote menu during start callback

---------

Co-authored-by: Nicholas Hastings <[email protected]>
This commit is contained in:
Mikusch
2026-08-24 19:40:41 +00:00
committed by GitHub
co-authored by Nicholas Hastings
parent 8c0aa36bbd
commit 61dea382c9
3 changed files with 17 additions and 24 deletions
+5
View File
@@ -97,6 +97,9 @@ void BaseMenuStyle::_CancelClientMenu(int client, MenuCancelReason reason, bool
RemoveClientFromWatch(client);
}
Handle_t hndl = menu ? menu->GetHandle() : BAD_HANDLE;
AutoHandleRooter ahr(hndl);
/* Fire callbacks */
mh->OnMenuCancel(menu, client, reason);
@@ -576,6 +579,8 @@ bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
CBaseMenuPlayer *player = GetMenuPlayer(client);
menu_states_t &states = player->states;
AutoHandleRooter ahr(states.menu ? states.menu->GetHandle() : BAD_HANDLE);
player->bAutoIgnore = true;
IMenuPanel *display = g_Menus.RenderMenu(client, states, order);
if (!display)
+12 -1
View File
@@ -41,6 +41,7 @@
#include <const.h>
#include <ITranslator.h>
#include "logic_bridge.h"
#include "AutoHandleRooter.h"
float g_next_vote = 0.0f;
@@ -363,7 +364,14 @@ void VoteMenuHandler::StartVoting()
m_bStarted = true;
m_pHandler->OnMenuVoteStart(m_pCurMenu);
IBaseMenu *menu = m_pCurMenu;
AutoHandleRooter ahr(menu->GetHandle());
m_pHandler->OnMenuVoteStart(menu);
if (!m_bStarted)
{
return;
}
m_displayTimer = g_Timers.CreateTimer(this, 1.0, NULL, TIMER_FLAG_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
@@ -426,6 +434,7 @@ void VoteMenuHandler::EndVoting()
IBaseMenu *menu = m_pCurMenu;
IMenuHandler *handler = m_pHandler;
InternalReset();
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
handler->OnMenuVoteCancel(menu, VoteCancel_Generic);
handler->OnMenuEnd(menu, MenuEnd_VotingCancelled);
return;
@@ -455,6 +464,7 @@ void VoteMenuHandler::EndVoting()
IBaseMenu *menu = m_pCurMenu;
IMenuHandler *handler = m_pHandler;
InternalReset();
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
handler->OnMenuVoteCancel(menu, VoteCancel_NoVotes);
handler->OnMenuEnd(menu, MenuEnd_VotingCancelled);
return;
@@ -486,6 +496,7 @@ void VoteMenuHandler::EndVoting()
InternalReset();
/* Send vote info */
AutoHandleRooter ahr(menu ? menu->GetHandle() : BAD_HANDLE);
handler->OnMenuVoteResults(menu, &vote);
handler->OnMenuEnd(menu, MenuEnd_VotingDone);
}
-23
View File
@@ -243,27 +243,4 @@ private:
extern HandleSystem g_HandleSys;
struct AutoHandleRooter
{
public:
AutoHandleRooter(Handle_t hndl)
{
if (hndl != BAD_HANDLE)
this->hndl = g_HandleSys.FastCloneHandle(hndl);
else
this->hndl = BAD_HANDLE;
}
~AutoHandleRooter()
{
if (hndl != BAD_HANDLE)
{
HandleSecurity sec(g_pCoreIdent, g_pCoreIdent);
g_HandleSys.FreeHandle(hndl, &sec);
}
}
private:
Handle_t hndl;
};
#endif //_INCLUDE_SOURCEMOD_HANDLESYSTEM_H_