[Scummvm-cvs-logs] SF.net SVN: scummvm: [23450] scummvm/trunk/engines/simon/sound.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jul 20 22:37:45 CEST 2006


Revision: 23450
          http://svn.sourceforge.net/scummvm/?rev=23450&view=rev
Author:   fingolfin
Date:     2006-07-09 02:43:56 -0700 (Sun, 09 Jul 2006)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/engines/simon/sound.cpp

Modified: scummvm/trunk/engines/simon/sound.cpp
===================================================================
--- scummvm/trunk/engines/simon/sound.cpp	2006-07-09 09:40:44 UTC (rev 23449)
+++ scummvm/trunk/engines/simon/sound.cpp	2006-07-09 09:43:56 UTC (rev 23450)
@@ -144,8 +144,13 @@
 	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 @@
 
 	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






More information about the Scummvm-git-logs mailing list