diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index 57a8372b2..ebc89efac 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -357,7 +357,7 @@ public: 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 dbd63002b..1df7e5d39 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -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 {