From cdbee9972aca6da04ff8a1d0b564e8758782f9fb Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sat, 5 Oct 2013 00:24:30 +0100 Subject: SWORD25: Fix possible error in sound engine when loading a savegame The error occurred when the save game was saved early in the game before all the sound handles had been used. The unused handles only had the handle type initialised (as kFreeHandle) so all the other fields had random values. After loading the game the sound engine could erroneously try to play one of these sound handle resulting in an error. --- engines/sword25/sfx/soundengine.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp index d90849e449..8ff1b0cf2a 100644 --- a/engines/sword25/sfx/soundengine.cpp +++ b/engines/sword25/sfx/soundengine.cpp @@ -339,7 +339,10 @@ bool SoundEngine::persist(OutputPersistenceBlock &writer) { _handles[i].type = kFreeHandle; writer.writeString(_handles[i].fileName); - writer.write(_handles[i].sndType); + if (_handles[i].type == kFreeHandle) + writer.write((int32)-1); + else + writer.write(_handles[i].sndType); writer.write(_handles[i].volume); writer.write(_handles[i].pan); writer.write(_handles[i].loop); @@ -381,7 +384,7 @@ bool SoundEngine::unpersist(InputPersistenceBlock &reader) { reader.read(layer); if (reader.isGood()) { - if (sndType != kFreeHandle) + if (sndType != -1) playSoundEx(fileName, (SOUND_TYPES)sndType, volume, pan, loop, loopStart, loopEnd, layer, i); } else return false; -- cgit v1.2.3