From 85bac5506e3b022cfd710aa31d97397c11a6cc20 Mon Sep 17 00:00:00 2001 From: Gareth Francis Date: Thu, 11 Apr 2024 18:56:09 +0100 Subject: [PATCH] Prevent sound fade in/out from hitting assertion in fapproach --- src/GameSoundManager.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index 1fa16d67f1..6ebb315bd6 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -554,7 +554,12 @@ void GameSoundManager::Update( float fDeltaTime ) { case FADE_NONE: break; case FADE_OUT: - fapproach( fVolume, g_fDimVolume, fDeltaTime/fFadeOutSpeed ); + if( fFadeOutSpeed > 0.0 ) { + fapproach( fVolume, g_fDimVolume, fDeltaTime/fFadeOutSpeed ); + } else { + // Treat an invalid fade speed as instant + fVolume = g_fDimVolume; + } if( std::abs(fVolume-g_fDimVolume) < 0.001f ) g_FadeState = FADE_WAIT; break; @@ -564,7 +569,12 @@ void GameSoundManager::Update( float fDeltaTime ) g_FadeState = FADE_IN; break; case FADE_IN: - fapproach( fVolume, g_fOriginalVolume, fDeltaTime/fFadeInSpeed ); + if( fFadeInSpeed > 0.0 ) { + fapproach( fVolume, g_fOriginalVolume, fDeltaTime/fFadeInSpeed ); + } else { + // Treat an invalid fade speed as instant + fVolume = g_fOriginalVolume; + } if( std::abs(fVolume-g_fOriginalVolume) < 0.001f ) g_FadeState = FADE_NONE; break;