aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2006-07-09 09:43:56 +0000
committerMax Horn2006-07-09 09:43:56 +0000
commit51ad5aa7197b3ced348ae37e2bc1586cb25dff3e (patch)
treedb4437ea0c612228ca51cb054eb7fedda87b7cc8 /engines
parenteaff9344a457d14a90175d8fe613d0cd952290f9 (diff)
downloadscummvm-rg350-51ad5aa7197b3ced348ae37e2bc1586cb25dff3e.tar.gz
scummvm-rg350-51ad5aa7197b3ced348ae37e2bc1586cb25dff3e.tar.bz2
scummvm-rg350-51ad5aa7197b3ced348ae37e2bc1586cb25dff3e.zip
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
Diffstat (limited to 'engines')
-rw-r--r--engines/simon/sound.cpp18
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