Fixed a crash with A_ClearOverlays

This commit is contained in:
Leonard2 2016-07-16 16:07:31 +02:00
parent 39042dc4bf
commit e482a54389

View file

@ -1171,50 +1171,39 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ClearOverlays)
PARAM_INT_OPT(stop) { stop = 0; } PARAM_INT_OPT(stop) { stop = 0; }
PARAM_BOOL_OPT(safety) { safety = true; } PARAM_BOOL_OPT(safety) { safety = true; }
if (!self->player) if (self->player == nullptr)
ACTION_RETURN_INT(0); ACTION_RETURN_INT(0);
player_t *player = self->player;
if (!start && !stop) if (!start && !stop)
{ {
start = INT_MIN; start = INT_MIN;
stop = safety ? PSP_TARGETCENTER - 1 : INT_MAX; stop = safety ? PSP_TARGETCENTER - 1 : INT_MAX;
} }
int count = 0; unsigned int count = 0;
DPSprite *pspr = player->psprites; int id;
int startID = (pspr != nullptr) ? pspr->GetID() : start;
bool first = true;
while (pspr != nullptr)
{
if (pspr->GetID() == startID)
{
if (first)
first = false;
else
break;
}
int id = pspr->GetID();
//Do not wipe out layer 0. Ever. for (DPSprite *pspr = self->player->psprites; pspr != nullptr; pspr = pspr->GetNext())
if (!id || id < start) {
id = pspr->GetID();
if (id < start || id == 0)
continue; continue;
if (id > stop) else if (id > stop)
break; break;
if (safety) if (safety)
{ {
if (id >= PSP_TARGETCENTER) if (id >= PSP_TARGETCENTER)
break; break;
else if ((id >= PSP_STRIFEHANDS && id <= PSP_WEAPON) || (id == PSP_FLASH)) else if (id == PSP_STRIFEHANDS || id == PSP_WEAPON || id == PSP_FLASH)
continue; continue;
} }
// [MC]Don't affect non-hardcoded layers unless it's really desired.
pspr->SetState(nullptr); pspr->SetState(nullptr);
count++; count++;
pspr = pspr->GetNext();
} }
ACTION_RETURN_INT(count); ACTION_RETURN_INT(count);
} }