diff options
-rw-r--r-- | engines/simon/sound.cpp | 18 |
1 files 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 |