- Re-jigged DoJump() to not be recursive so that 0-tic A_Jump* loops are no longer

able to potentially blow up the stack.

SVN r3902 (scripting)
This commit is contained in:
Randy Heit 2012-10-23 03:19:17 +00:00
parent 47eec0b275
commit d0c91083bc
3 changed files with 19 additions and 1 deletions

View file

@ -205,6 +205,7 @@ enum EObjectFlags
OF_JustSpawned = 1 << 8, // Thinker was spawned this tic OF_JustSpawned = 1 << 8, // Thinker was spawned this tic
OF_SerialSuccess = 1 << 9, // For debugging Serialize() calls OF_SerialSuccess = 1 << 9, // For debugging Serialize() calls
OF_Sentinel = 1 << 10, // Object is serving as the sentinel in a ring list OF_Sentinel = 1 << 10, // Object is serving as the sentinel in a ring list
OF_StateChanged = 1 << 11, // Used by A_Jump* functions to feed back to SetState()
}; };
template<class T> class TObjPtr; template<class T> class TObjPtr;

View file

@ -482,8 +482,17 @@ bool AActor::SetState (FState *newstate, bool nofunction)
{ {
// Check whether the called action function resulted in destroying the actor // Check whether the called action function resulted in destroying the actor
if (ObjectFlags & OF_EuthanizeMe) if (ObjectFlags & OF_EuthanizeMe)
{
return false; return false;
} }
if (ObjectFlags & OF_StateChanged)
{ // The action was an A_Jump-style function that wants to change the next state.
ObjectFlags &= ~OF_StateChanged;
newstate = state;
tics = 0; // make sure we loop and set the new state properly
continue;
}
}
newstate = newstate->GetNextState(); newstate = newstate->GetNextState();
} while (tics == 0); } while (tics == 0);

View file

@ -610,7 +610,15 @@ static void DoJump(AActor *self, AActor *stateowner, FState *callingstate, FStat
} }
else if (callingstate == self->state) else if (callingstate == self->state)
{ {
self->SetState(jumpto); // Rather than using self->SetState(jumpto) to set the state,
// set the state directly. Since this function is only called by
// action functions, which are only called by SetState(), we
// know that somewhere above us in the stack, a SetState()
// call is waiting for us to return. We use the flag OF_StateChanged
// to cause it to bypass the normal next state mechanism and use
// the one we set here instead.
self->state = jumpto;
self->ObjectFlags |= OF_StateChanged;
} }
else else
{ // something went very wrong. This should never happen. { // something went very wrong. This should never happen.