From 473221bb339944ff9205e29a6a958d4c2c52e945 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Nov 2022 10:27:54 +0100 Subject: [PATCH] - fixed SoundEngine::isValidSoundId. This never accounted for linked and random sounds. It never got noticed because it never was used to validate anything essential before. --- src/common/audio/sound/s_soundinternal.h | 2 +- src/common/utility/tarray.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index 57a8372b2c9..ebc89efacb8 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -357,7 +357,7 @@ class SoundEngine bool isValidSoundId(FSoundID sid) { int id = sid.index(); - return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative && S_sfx[id].lumpnum != sfx_empty; + return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative && (S_sfx[id].lumpnum != sfx_empty || S_sfx[id].bRandomHeader || S_sfx[id].link != sfxinfo_t::NO_LINK); } template bool EnumerateChannels(func callback) diff --git a/src/common/utility/tarray.h b/src/common/utility/tarray.h index dbd63002b0b..1df7e5d39c1 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -316,9 +316,16 @@ class TArray // 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 {