fixed destruction of the sound module

main
Martin Felis (berta) 2010-11-01 22:22:50 +01:00
parent 6f3d78dab0
commit a1be34e1a4
2 changed files with 19 additions and 0 deletions

View File

@ -66,6 +66,13 @@ int SoundBase::OnInit(int argc, char* argv[]) {
void SoundBase::OnDestroy() { void SoundBase::OnDestroy() {
LogDebug ("Sound Destroy"); LogDebug ("Sound Destroy");
// stop music
HaltMusic();
// stop and clear all samples
mSamples.clear();
Mix_CloseAudio(); Mix_CloseAudio();
SoundInstance = NULL; SoundInstance = NULL;
@ -155,6 +162,17 @@ void SoundBase::PlayMusic (const std::string &music_name) {
Mix_PlayMusic(mCurrentMusic, -1); 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 * Global Functions
*/ */

View File

@ -37,6 +37,7 @@ class SoundBase : public Module {
void PlaySoundLoop (const std::string &sound_name, int count); void PlaySoundLoop (const std::string &sound_name, int count);
void HaltSoundLoop (const std::string &sound_name); void HaltSoundLoop (const std::string &sound_name);
void PlayMusic (const std::string &music_name); void PlayMusic (const std::string &music_name);
void HaltMusic ();
protected: protected:
/** \brief Initializes the system */ /** \brief Initializes the system */