Skip to content

Commit

Permalink
- fixed SoundEngine::isValidSoundId.
Browse files Browse the repository at this point in the history
This never accounted for linked and random sounds. It never got noticed because it never was used to validate anything essential before.
  • Loading branch information
coelckers committed Nov 25, 2022
1 parent 8206c29 commit 473221b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/audio/sound/s_soundinternal.h
Expand Up @@ -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<class func> bool EnumerateChannels(func callback)
Expand Down
7 changes: 7 additions & 0 deletions src/common/utility/tarray.h
Expand Up @@ -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
{
Expand Down

0 comments on commit 473221b

Please sign in to comment.