From 7ec33b6b9283a2036b62147a3bd6822d2a01a2e8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 23 Sep 2019 15:42:03 +0300 Subject: [PATCH] - fixed crash when setting sound pitch on non-existing channel This applies to a lack of free channels, -nosound command line switch, missing OpenAL library, sound initialization failures, ... https://forum.zdoom.org/viewtopic.php?t=65926 --- src/sound/s_sound.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sound/s_sound.cpp b/src/sound/s_sound.cpp index d00dc145e..6d3a9e404 100644 --- a/src/sound/s_sound.cpp +++ b/src/sound/s_sound.cpp @@ -1199,10 +1199,10 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO case SOURCE_Unattached: chan->Point[0] = pt->X; chan->Point[1] = pt->Y; chan->Point[2] = pt->Z; break; default: break; } - } - if (spitch > 0.0) - S_SetPitch(chan, spitch); + if (spitch > 0.0) + S_SetPitch(chan, spitch); + } return chan; } @@ -1849,6 +1849,7 @@ void S_ChangeSoundPitch(AActor *actor, int channel, double pitch) void S_SetPitch(FSoundChan *chan, float pitch) { + assert(chan != nullptr); GSnd->ChannelPitch(chan, MAX(0.0001f, pitch)); chan->Pitch = MAX(1, int(float(NORM_PITCH) * pitch)); }