From 9df7f7385cbde0b05931a7faafa10d65e615e429 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 1 Feb 2009 21:11:03 +0000 Subject: [PATCH] - Cleanup - This time fixed the real cause of the mismatching malloc / delete[] call. svn-id: r36191 --- engines/kyra/sound.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp index a1088bf75d8..f3c4789ddf5 100644 --- a/engines/kyra/sound.cpp +++ b/engines/kyra/sound.cpp @@ -125,15 +125,28 @@ void Sound::voicePlayFromList(Common::List fileList) { Audio::AppendableAudioStream *out = Audio::makeAppendableAudioStream(22050, Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED); for (Common::List::iterator i = fileList.begin(); i != fileList.end(); i++) { - uint32 fileSize = 0; - uint8 *file = _vm->resource()->fileData(*i, &fileSize); - Common::MemoryReadStream vocStream(file, fileSize, false); + Common::SeekableReadStream *file = _vm->resource()->createReadStream(*i); + + // TODO: Maybe output an warning like "file not found"? + if (!file) + continue; int size, rate; - uint8 *data = Audio::loadVOCFromStream(vocStream, size, rate); - out->queueBuffer(data, size); - delete[] file; + uint8 *data = Audio::loadVOCFromStream(*file, size, rate); + delete file; + + // FIXME/HACK: While loadVOCStream uses malloc / realloc, + // AppendableAudioStream uses delete[] to free the passed buffer. + // As a consequence we just 'move' the data to a buffer allocated + // via new[]. + uint8 *vocBuffer = new uint8[size]; + assert(vocBuffer); + memcpy(vocBuffer, data, size); + free(data); + + out->queueBuffer(vocBuffer, size); } + out->finish(); _soundChannels[h].file = *fileList.begin();