diff --git a/src/platform/C4SoundSystem.cpp b/src/platform/C4SoundSystem.cpp index 6c64d270c..b3d4d8010 100644 --- a/src/platform/C4SoundSystem.cpp +++ b/src/platform/C4SoundSystem.cpp @@ -50,11 +50,13 @@ bool C4SoundSystem::Init() #if AUDIO_TK == AUDIO_TK_SDL_MIXER Mix_AllocateChannels(C4MaxSoundInstances); #endif + initialized = true; return true; } void C4SoundSystem::Clear() { + initialized = false; ClearEffects(); Modifiers.Clear(); // Close sound file @@ -122,15 +124,13 @@ C4SoundEffect* C4SoundSystem::GetEffect(const char *szSndName) C4SoundInstance *C4SoundSystem::NewEffect(const char *szSndName, bool fLoop, int32_t iVolume, C4Object *pObj, int32_t iCustomFalloffDistance, int32_t iPitch, C4SoundModifier *modifier) { // Sound not active - if (!Config.Sound.RXSound) return nullptr; + if (!initialized || !Config.Sound.RXSound) return nullptr; // Get sound C4SoundEffect *csfx; if (!(csfx = GetEffect(szSndName))) { // Warn about missing or incorrectly spelled sound to allow finding mistakes earlier. -#if !defined(USE_CONSOLE) DebugLogF("Warning: could not find sound matching '%s'", szSndName); -#endif return nullptr; } // Play diff --git a/src/platform/C4SoundSystem.h b/src/platform/C4SoundSystem.h index e6b445486..24cc7ba98 100644 --- a/src/platform/C4SoundSystem.h +++ b/src/platform/C4SoundSystem.h @@ -55,6 +55,7 @@ public: protected: C4Group SoundFile; C4SoundEffect *FirstSound{nullptr}; // TODO: Add a hash map for sound lookup. Also add a global list for all running sound instances. + bool initialized{false}; void ClearEffects(); C4SoundEffect* GetEffect(const char *szSound); int32_t RemoveEffect(const char *szFilename);