- added runtime checks for the state usage flags.

This commit is contained in:
Christoph Oelckers 2016-11-15 00:18:57 +01:00
parent 4f998fa879
commit 647e1399f1
4 changed files with 26 additions and 0 deletions

View file

@ -128,6 +128,13 @@ bool ACustomInventory::CallStateChain (AActor *actor, FState *state)
while (state != NULL)
{
if (!(state->UseFlags & SUF_ITEM))
{
auto so = FState::StaticFindStateOwner(state);
Printf("State %s.%d not flagged for use in CustomInventory state chains.\n", so->TypeName.GetChars(), int(state - so->OwnedStates));
return false;
}
this->state = state;
nextstate = NULL; // assume no jump

View file

@ -626,6 +626,14 @@ bool AActor::SetState (FState *newstate, bool nofunction)
{
prevsprite = -1;
}
if (!(newstate->UseFlags & SUF_ACTOR))
{
auto so = FState::StaticFindStateOwner(newstate);
Printf("State %s.%d in %s not flagged for use as an actor sprite\n", so->TypeName.GetChars(), int(newstate - so->OwnedStates), GetClass()->TypeName.GetChars());
state = nullptr;
Destroy();
return false;
}
state = newstate;
tics = GetTics(newstate);
renderflags = (renderflags & ~RF_FULLBRIGHT) | ActorRenderFlags::FromInt (newstate->GetFullbright());

View file

@ -296,6 +296,16 @@ void DPSprite::SetState(FState *newstate, bool pending)
Destroy();
return;
}
if (!(newstate->UseFlags & (SUF_OVERLAY|SUF_WEAPON))) // Weapon and overlay are mostly the same, the main difference is that weapon states restrict the self pointer to class Actor.
{
auto so = FState::StaticFindStateOwner(newstate);
Printf("State %s.%d not flagged for use in overlays or weapons\n", so->TypeName.GetChars(), int(newstate - so->OwnedStates));
State = nullptr;
Destroy();
return;
}
State = newstate;
if (newstate->sprite != SPR_FIXED)

View file

@ -2437,6 +2437,7 @@ void ZCCCompiler::CompileStates()
auto sl = static_cast<ZCC_StateLine *>(st);
FState state;
memset(&state, 0, sizeof(state));
state.UseFlags = flags;
if (sl->Sprite->Len() != 4)
{
Error(sl, "Sprite name must be exactly 4 characters. Found '%s'", sl->Sprite->GetChars());