- fixed failiure to initialize the ambient tags array.

Also adding range checks to all places where it gets used. This is from CON code so proper values are never guaranteed.
This commit is contained in:
Christoph Oelckers 2022-11-24 09:01:44 +01:00
parent 13e19bad36
commit 4d6920e80b
4 changed files with 19 additions and 17 deletions

View file

@ -316,9 +316,16 @@ public:
// Returns a reference to the last element
T &Last() const
{
assert(Count > 0);
return Array[Count-1];
}
T SafeGet (size_t index, const T& defaultval) const
{
if (index <= Count) return Array[index];
else return defaultval;
}
// returns address of first element
T *Data() const
{

View file

@ -1760,23 +1760,23 @@ int ParseState::parse(void)
break;
case concmd_ifsoundid:
insptr++;
parseifelse((short)*insptr == ambienttags[g_ac->spr.detail].lo);
parseifelse((short)*insptr == ambienttags.SafeGet(g_ac->spr.detail, {}).lo);
break;
case concmd_ifsounddist:
insptr++;
if (*insptr == 0)
parseifelse(ambienttags[g_ac->spr.detail].hi > g_x);
parseifelse(ambienttags.SafeGet(g_ac->spr.detail, {}).hi > g_x);
else if (*insptr == 1)
parseifelse(ambienttags[g_ac->spr.detail].hi < g_x);
parseifelse(ambienttags.SafeGet(g_ac->spr.detail, {}).hi < g_x);
break;
case concmd_soundtag:
insptr++;
S_PlayActorSound(ambienttags[g_ac->spr.detail].lo, g_ac);
S_PlayActorSound(ambienttags.SafeGet(g_ac->spr.detail, {}).lo, g_ac);
break;
case concmd_soundtagonce:
insptr++;
if (!S_CheckActorSoundPlaying(g_ac, ambienttags[g_ac->spr.detail].lo))
S_PlayActorSound(ambienttags[g_ac->spr.detail].lo, g_ac);
if (!S_CheckActorSoundPlaying(g_ac, ambienttags.SafeGet(g_ac->spr.detail, {}).lo))
S_PlayActorSound(ambienttags.SafeGet(g_ac->spr.detail, {}).lo, g_ac);
break;
case concmd_soundonce:
insptr++;

View file

@ -563,12 +563,6 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray<DDukeActor*>*
case SHOTGUNSHELL:
initshell(actj, act, act->spr.picnum == SHELL);
break;
case SOUNDFX:
{
act->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
ChangeActorStat(act, STAT_ZOMBIEACTOR);
}
break;
case EXPLOSION2:
case EXPLOSION3:
case BURNING:

View file

@ -164,16 +164,17 @@ class DukeDummyCtrl : DukeActor
class DukeSoundFX : DukeActor
{
default
{
statnum STAT_ZOMBIEACTOR;
}
override void StaticSetup()
{
self.cstat = CSTAT_SPRITE_INVISIBLE;
self.detail = dlevel.addambient(self.hitag, self.lotag);
self.lotag = self.hitag = 0;
}
// this actor needs to start on STAT_DEFAULT.
override void Initialize()
{
self.ChangeStat(STAT_ZOMBIEACTOR);
}
}