Skip to content

Commit

Permalink
Merge pull request ddnet#9434 from Robyt3/Sound-UnloadSample-Assert-Fix
Browse files Browse the repository at this point in the history
Fix assertion when sound fails to be loaded
  • Loading branch information
def- authored Dec 28, 2024
2 parents c7a32ab + f75acbe commit 061b85c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/engine/client/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,25 @@ void CSound::UnloadSample(int SampleId)
if(SampleId == -1)
return;

Stop(SampleId);

// Free data
dbg_assert(SampleId >= 0 && SampleId < NUM_SAMPLES, "SampleId invalid");
const CLockScope LockScope(m_SoundLock);
CSample &Sample = m_aSamples[SampleId];
free(Sample.m_pData);
Sample.m_pData = nullptr;

if(Sample.IsLoaded())
{
// Stop voices using this sample
for(auto &Voice : m_aVoices)
{
if(Voice.m_pSample == &Sample)
{
Voice.m_pSample = nullptr;
}
}

// Free data
free(Sample.m_pData);
Sample.m_pData = nullptr;
}

// Free slot
if(Sample.m_NextFreeSampleIndex == SAMPLE_INDEX_USED)
Expand Down

0 comments on commit 061b85c

Please sign in to comment.