From 2da9fa5a6edd962acca228706a2f2d4465827015 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 15 May 2010 08:38:19 +0000 Subject: Rewrote playMovieSound() to keep it from hogging memory in the resource manager. Perhaps this will finally fix the mysterious bug #2976008 ("BS2: Game lockup in British Museum"). svn-id: r49036 --- engines/sword2/sound.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'engines/sword2') diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp index 5e67ce9adf..e36c946eba 100644 --- a/engines/sword2/sound.cpp +++ b/engines/sword2/sound.cpp @@ -217,13 +217,38 @@ void Sound::playMovieSound(int32 res, int type) { assert(_vm->_resman->fetchType(data) == WAV_FILE); - // In PSX version we have nothing to skip here, as data starts right away - if (!Sword2Engine::isPsx()) { - data += ResHeader::size(); - len -= ResHeader::size(); + // We want to close the resource right away, so to be safe we make a + // private copy of the sound; + byte *soundData = (byte *)malloc(len); + + if (soundData) { + memcpy(soundData, data, len); + + Common::MemoryReadStream *stream = new Common::MemoryReadStream(soundData, len, DisposeAfterUse::YES); + + // In PSX version we have nothing to skip here, as data starts + // right away. + if (!Sword2Engine::isPsx()) { + stream->seek(ResHeader::size()); + } + + Audio::RewindableAudioStream *input = 0; + + if (Sword2Engine::isPsx()) { + input = Audio::makeVagStream(stream); + } else { + input = Audio::makeWAVStream(stream, DisposeAfterUse::YES); + } + + _vm->_mixer->playStream( + Audio::Mixer::kMusicSoundType, handle, input, + -1, Audio::Mixer::kMaxChannelVolume, 0, + DisposeAfterUse::YES, false, isReverseStereo()); + } else { + warning("Sound::playMovieSound: Could not allocate %d bytes\n", len); } - _vm->_sound->playFx(handle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType); + _vm->_resman->closeResource(res); } void Sound::stopMovieSounds() { -- cgit v1.2.3