From 92310f66f033ad469441e183cd0966bc73b78604 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 19 Jan 2025 02:05:50 +0100 Subject: [PATCH] Fix running timedemo if sound is disabled (s_noSound 1), fix #163 By adding some nullpointer checks --- neo/sound/snd_emitter.cpp | 3 ++- neo/sound/snd_world.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/neo/sound/snd_emitter.cpp b/neo/sound/snd_emitter.cpp index e0230b35e..bd241b81a 100644 --- a/neo/sound/snd_emitter.cpp +++ b/neo/sound/snd_emitter.cpp @@ -952,7 +952,8 @@ void idSoundEmitterLocal::StopSound( const s_channelType channel ) { chan->ALStop(); // if this was an onDemand sound, purge the sample now - if ( chan->leadinSample->onDemand ) { + // Note: if sound is disabled (s_noSound 1), leadinSample can be NULL + if ( chan->leadinSample && chan->leadinSample->onDemand ) { chan->leadinSample->PurgeSoundSample(); } diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index a346d6e4d..9edd250f2 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -2148,10 +2148,13 @@ float idSoundWorldLocal::FindAmplitude( idSoundEmitterLocal *sound, const int lo sourceBuffer[j] = j & 1 ? 32767.0f : -32767.0f; } } else { - int offset = (localTime - localTriggerTimes); // offset in samples - int size = ( looping ? chan->soundShader->entries[0]->LengthIn44kHzSamples() : chan->leadinSample->LengthIn44kHzSamples() ); - short *amplitudeData = (short *)( looping ? chan->soundShader->entries[0]->amplitudeData : chan->leadinSample->amplitudeData ); + idSoundSample* sample = looping ? chan->soundShader->entries[0] : chan->leadinSample; + if ( sample == NULL ) // DG: this happens if sound is disabled (s_noSound 1) + continue; + int offset = (localTime - localTriggerTimes); // offset in samples + int size = sample->LengthIn44kHzSamples(); + short *amplitudeData = (short *)( sample->amplitudeData ); if ( amplitudeData ) { // when the amplitudeData is present use that fill a dummy sourceBuffer // this is to allow for amplitude based effect on hardware audio solutions