ref: 43f6dc56eda1aa1c32d0af6dfdec8cf1b1f478eb
parent: 66cf5dd1d216b71899831fe8cbb676057c5757f7
author: Simon Howard <[email protected]>
date: Sat Mar 5 13:32:55 EST 2011
Behave correctly when we run out of memory. Subversion-branch: /branches/strife-branch Subversion-revision: 2289
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -73,10 +73,10 @@
static Uint16 mixer_format;
static int mixer_channels;
static boolean use_sfx_prefix;
-static void (*ExpandSoundData)(sfxinfo_t *sfxinfo,
- byte *data,
- int samplerate,
- int length) = NULL;
+static boolean (*ExpandSoundData)(sfxinfo_t *sfxinfo,
+ byte *data,
+ int samplerate,
+ int length) = NULL;
// Doubly-linked list of allocated sounds.
// When a sound is played, it is moved to the head, so that the oldest
@@ -300,10 +300,10 @@
// Returns number of clipped samples.
// DWF 2008-02-10 with cleanups by Simon Howard.
-static void ExpandSoundData_SRC(sfxinfo_t *sfxinfo,
- byte *data,
- int samplerate,
- int length)
+static boolean ExpandSoundData_SRC(sfxinfo_t *sfxinfo,
+ byte *data,
+ int samplerate,
+ int length)
{
SRC_DATA src_data;
uint32_t i, abuf_index=0, clipped=0;
@@ -342,6 +342,12 @@
alen = src_data.output_frames_gen * 4;
chunk = AllocateSound(sfxinfo, src_data.output_frames_gen * 4);
+
+ if (chunk == NULL)
+ {
+ return false;
+ }
+
expanded = (int16_t *) chunk->abuf;
// Convert the result back into 16-bit integers.
@@ -399,6 +405,8 @@
sfxinfo->name, clipped,
400.0 * clipped / chunk->alen);
}
+
+ return true;
}
#endif
@@ -485,10 +493,10 @@
// Generic sound expansion function for any sample rate.
// Returns number of clipped samples (always 0).
-static void ExpandSoundData_SDL(sfxinfo_t *sfxinfo,
- byte *data,
- int samplerate,
- int length)
+static boolean ExpandSoundData_SDL(sfxinfo_t *sfxinfo,
+ byte *data,
+ int samplerate,
+ int length)
{
SDL_AudioCVT convertor;
Mix_Chunk *chunk;
@@ -506,6 +514,11 @@
chunk = AllocateSound(sfxinfo, expanded_length);
+ if (chunk == NULL)
+ {
+ return false;
+ }
+
// If we can, use the standard / optimized SDL conversion routines.
if (samplerate <= mixer_freq
@@ -583,6 +596,8 @@
}
#endif /* #ifdef LOW_PASS_FILTER */
}
+
+ return true;
}
// Load and convert a sound effect
@@ -627,7 +642,10 @@
// Sample rate conversion
- ExpandSoundData(sfxinfo, data + 8, samplerate, length);
+ if (!ExpandSoundData(sfxinfo, data + 8, samplerate, length))
+ {
+ return false;
+ }
#ifdef DEBUG_DUMP_WAVS
{