diff --git a/engine/SoundBase.cc b/engine/SoundBase.cc index 8185e25..e32c1ed 100644 --- a/engine/SoundBase.cc +++ b/engine/SoundBase.cc @@ -66,6 +66,13 @@ int SoundBase::OnInit(int argc, char* argv[]) { void SoundBase::OnDestroy() { LogDebug ("Sound Destroy"); + + // stop music + HaltMusic(); + + // stop and clear all samples + mSamples.clear(); + Mix_CloseAudio(); SoundInstance = NULL; @@ -155,6 +162,17 @@ void SoundBase::PlayMusic (const std::string &music_name) { Mix_PlayMusic(mCurrentMusic, -1); } +void SoundBase::HaltMusic () { + if (!SoundInstance) { + LogError("Could not stop music: sound system not initialized!"); + } + + Mix_HaltMusic(); + Mix_FreeMusic(mCurrentMusic); + mCurrentMusic = NULL; +} + + /* * Global Functions */ diff --git a/engine/SoundBase.h b/engine/SoundBase.h index 077052a..2215b6b 100644 --- a/engine/SoundBase.h +++ b/engine/SoundBase.h @@ -37,6 +37,7 @@ class SoundBase : public Module { void PlaySoundLoop (const std::string &sound_name, int count); void HaltSoundLoop (const std::string &sound_name); void PlayMusic (const std::string &music_name); + void HaltMusic (); protected: /** \brief Initializes the system */