- implement limits for state loops to prevent infinite state freezes

This commit is contained in:
Rachael Alexanderson 2025-06-06 08:49:08 -04:00 committed by Rachael Alexanderson
commit 6b2b8a198f
2 changed files with 18 additions and 0 deletions

View file

@ -874,9 +874,17 @@ bool AActor::SetState (FState *newstate, bool nofunction)
if (debugfile && player && (player->cheats & CF_PREDICTING))
fprintf (debugfile, "for pl %d: SetState while predicting!\n", Level->PlayerNum(player));
int statelooplimit = 300000;
auto oldstate = state;
do
{
if (!(--statelooplimit))
{
Printf(TEXTCOLOR_RED "Infinite state loop in Actor '%s' state '%s'\n", GetClass()->TypeName.GetChars(), FState::StaticGetStateName(state).GetChars());
state = nullptr;
Destroy();
return false;
}
if (newstate == NULL)
{
state = NULL;

View file

@ -488,10 +488,20 @@ void DPSprite::SetState(FState *newstate, bool pending)
WF_USER1OK | WF_USER2OK | WF_USER3OK | WF_USER4OK);
}
int statelooplimit = 300000;
processPending = pending;
do
{
if (!(--statelooplimit))
{
Printf(TEXTCOLOR_RED "Infinite state loop in weapon state '%s'\n", FState::StaticGetStateName(State).GetChars());
State = nullptr;
Destroy();
return;
}
if (newstate == nullptr)
{ // Object removed itself.
Destroy();