From b41ae2dfdd5dea55802a6854e2993d0072f6dd33 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 9 Jun 2020 21:01:14 +0200 Subject: [PATCH] - do not allow playing sounds during PlayerFinishLevel. This gets called right before the level ends, any sound in here would play during the intermission or at the start of the next level. --- src/common/audio/sound/s_sound.cpp | 2 +- src/common/audio/sound/s_soundinternal.h | 6 ++++++ src/g_level.cpp | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 04a56491337..81bdf047a3d 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -378,7 +378,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, FVector3 pos, vel; FRolloffInfo *rolloff; - if (sound_id <= 0 || volume <= 0 || nosfx || nosound ) + if (sound_id <= 0 || volume <= 0 || nosfx || nosound || blockNewSounds) return NULL; // prevent crashes. diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index 5ecb6ee4821..77783389536 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -238,6 +238,7 @@ class SoundEngine TArray S_SoundCurve; TMap ResIdMap; TArray S_rnd; + bool blockNewSounds = false; private: void LinkChannel(FSoundChan* chan, FSoundChan** head); @@ -268,6 +269,11 @@ class SoundEngine } void EvictAllChannels(); + void BlockNewSounds(bool on) + { + blockNewSounds = on; + } + virtual int SoundSourceIndex(FSoundChan* chan) { return 0; } virtual void SetSource(FSoundChan* chan, int index) {} diff --git a/src/g_level.cpp b/src/g_level.cpp index 21010137ed7..85be99467fc 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -954,6 +954,8 @@ bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo) // Intermission stats for entire hubs G_LeavingHub(this, mode, thiscluster, &wminfo); + // Do not allow playing sounds in here - they'd never be able to play properly. + soundEngine->BlockNewSounds(true); for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) @@ -961,6 +963,7 @@ bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo) G_PlayerFinishLevel (i, mode, changeflags); } } + soundEngine->BlockNewSounds(false); if (mode == FINISH_SameHub) { // Remember the level's state for re-entry.