From bcc892ec81a5af68874f89135e2f5659271649e2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 26 Jul 2006 22:24:33 +0000 Subject: Make the midi player threadsafe (this should fix bug #1506583 "KYRA1: Crash on exceeded polyphony"). svn-id: r23605 --- engines/kyra/sound.cpp | 14 ++++++++++++++ engines/kyra/sound.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index ffe7ee1ac3..a279cb9499 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -118,6 +118,11 @@ SoundMidiPC::SoundMidiPC(MidiDriver *driver, Audio::Mixer *mixer, KyraEngine *en } SoundMidiPC::~SoundMidiPC() { + stopMusic(); + stopSoundEffect(); + + Common::StackLock lock(_mutex); + _driver->setTimerCallback(NULL, NULL); close(); } @@ -243,6 +248,8 @@ void SoundMidiPC::loadMusicFile(const char *file) { void SoundMidiPC::playMusic(uint8 *data, uint32 size) { stopMusic(); + Common::StackLock lock(_mutex); + _parserSource = data; _parser = MidiParser::createParser_XMIDI(); assert(_parser); @@ -278,6 +285,8 @@ void SoundMidiPC::loadSoundEffectFile(const char *file) { void SoundMidiPC::loadSoundEffectFile(uint8 *data, uint32 size) { stopSoundEffect(); + Common::StackLock lock(_mutex); + _soundEffectSource = data; _soundEffect = MidiParser::createParser_XMIDI(); assert(_soundEffect); @@ -296,6 +305,8 @@ void SoundMidiPC::loadSoundEffectFile(uint8 *data, uint32 size) { } void SoundMidiPC::stopMusic() { + Common::StackLock lock(_mutex); + _isPlaying = false; if (_parser) { _parser->unloadMusic(); @@ -311,6 +322,8 @@ void SoundMidiPC::stopMusic() { } void SoundMidiPC::stopSoundEffect() { + Common::StackLock lock(_mutex); + _sfxIsPlaying = false; if (_soundEffect) { _soundEffect->unloadMusic(); @@ -323,6 +336,7 @@ void SoundMidiPC::stopSoundEffect() { void SoundMidiPC::onTimer(void *refCon) { SoundMidiPC *music = (SoundMidiPC *)refCon; + Common::StackLock lock(music->_mutex); // this should be set to the fadeToBlack value static const uint32 musicFadeTime = 2 * 1000; diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h index a7de851349..0d932ae772 100644 --- a/engines/kyra/sound.h +++ b/engines/kyra/sound.h @@ -26,9 +26,12 @@ #include "common/stdafx.h" #include "common/scummsys.h" #include "common/file.h" +#include "common/mutex.h" + #include "sound/mididrv.h" #include "sound/midiparser.h" #include "sound/mixer.h" + #include "kyra/kyra.h" namespace Audio { @@ -200,6 +203,8 @@ private: byte *_parserSource; MidiParser *_soundEffect; byte *_soundEffectSource; + + Common::Mutex _mutex; }; class MixedSoundDriver : public Sound { -- cgit v1.2.3