From 51ad5aa7197b3ced348ae37e2bc1586cb25dff3e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 9 Jul 2006 09:43:56 +0000 Subject: Verify malloc worked. Apparently, simon (or FF?) sometimes tries to allocate extremly big (well, for the Nintendo DS at least :) chunks of memory, which lead to malloc failures. svn-id: r23450 --- engines/simon/sound.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/engines/simon/sound.cpp b/engines/simon/sound.cpp index 3429d1c31a..a49ac95433 100644 --- a/engines/simon/sound.cpp +++ b/engines/simon/sound.cpp @@ -144,8 +144,13 @@ void WavSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) { flags |= wavFlags; byte *buffer = (byte *)malloc(size); - _file->read(buffer, size); - _mixer->playRaw(handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE); + // Check whether malloc was successful. + // TODO: Maybe we can handle this more graceful, by reverting to a smaller + // buffer and reading the audio data one piece at a time? + if (buffer) { + _file->read(buffer, size); + _mixer->playRaw(handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE); + } } void VocSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) { @@ -167,8 +172,13 @@ void RawSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) { uint size = _file->readUint32BE(); byte *buffer = (byte *)malloc(size); - _file->read(buffer, size); - _mixer->playRaw(handle, buffer, size, 22050, flags | Audio::Mixer::FLAG_AUTOFREE); + // Check whether malloc was successful. + // TODO: Maybe we can handle this more graceful, by reverting to a smaller + // buffer and reading the audio data one piece at a time? + if (buffer) { + _file->read(buffer, size); + _mixer->playRaw(handle, buffer, size, 22050, flags | Audio::Mixer::FLAG_AUTOFREE); + } } #ifdef USE_MAD -- cgit v1.2.3