SDL_Mixer crash

I’ve been using SDL_Mixer in my shipping Mac game Midnight Mansion HD. I’ve started porting this to Windows, and have run into crashing problems on startup when loading WAVE sounds with SDL_Mixer. I’m wondering if any others have run into this?

You can duplicate the problem easily by pasting the code below into the playwave.c demo that comes with SDL_Mixer and compile it (and paste in the SDL 1.3 dll and SDL_Mixer dll into its folder so the demo can run). It’ll crash at startup.

Even more frustrating, this crashing does not occur when you enable the debugger. It starts up just fine. This is in Visual Studio 10.

I can upload the 79 sound effects I’m using if desired. I’ve tried isolating it to specific effects that are causing the crash (the first 12 or so load just fine), but too many do so. The effects play just fine in Windows Media Player.

Any thoughts? Again, this works fine on the Mac side.

Oh, and the crash occurs when the Mix_LoadWAV() line is executed. But again, I can’t debug it, since the crashing does NOT occur when debugging is enabled.



short gAudioWasInitialized = 0;
short gNumChannels = 0;
short gNumSounds = 0;
short gNumReservedChannels = 0;

Mix_Chunk **gSounds = NULL; // Array that stores references to all sound effects

// LoadAndSetupSounds
// numReservedChannels indicates how many channels, starting at index 0, a reserved for looping sounds.

short LoadAndSetupSounds( short numChannels, short numReservedChannels, short numSoundsToLoad, char *soundsPath)
int n, resID, result;
char filePath[ 255 ], soundsFolderPath[500];

	// Copy the path into a local string, so we can call other routines to get directories
	// without messing this one up.
strcpy(soundsFolderPath, soundsPath);

result = Mix_Init( MIX_INIT_OGG ); // returns bitwise mask of all currently inited music loaders

gNumChannels = numChannels;
gNumReservedChannels = numReservedChannels;

		// Allocate memory for buffers array. One buffer element for each sound effect we're going to load.
gSounds = (Mix_Chunk **)calloc(numSoundsToLoad, sizeof(Mix_Chunk *));
if (gSounds == NULL)
	return -1;

	// open 44.1KHz, signed 16bit, system byte order stereo audio, using 1024 byte chunks 
	// Smaller chunks result in less audio latency, but too small a chunk may result in cracking/popping. Increase size if it cracks/pops.
	// Make sure chunks are a power of 2!
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) // 2 channels (for stereo panning of sounds)
	printf("Unable to initialize audio: %s\n", Mix_GetError());
	gAudioWasInitialized = 0;
	gAudioWasInitialized = 1;

printf("Allocating sound channels...\n");

if (gAudioWasInitialized)
	Mix_AllocateChannels( gNumChannels );
		// No sounds will automatically play channels 0 - gNumReservedChannels-1
	Mix_ReserveChannels( gNumReservedChannels );

printf("Loading sounds...\n");

	// Load the sounds
if (gAudioWasInitialized)
	for (n = 0; n < numSoundsToLoad; n++)
		resID = 128 + n;
			// Look for a WAV first. Path is something like "../../Game Data/Sounds/00128.wav"
		sprintf(filePath, "%s00%d.wav", soundsFolderPath, resID);

		printf("Loading sound: %s \n", filePath);
		gSounds[n] = Mix_LoadWAV(filePath);
			// If we couldn't find a WAV file, try looking for an OGG file
		if (gSounds[n] == NULL)
			sprintf(filePath, "%s00%d.ogg", soundsFolderPath, resID);
			gSounds[n] = Mix_LoadWAV(filePath);

		if (gSounds[n] == NULL)
			printf("Unable to load WAV file for sound %d: %s\n", n, Mix_GetError());
//			return -2;

return 0; // no error


Here is a link to the sounds I’m using, in case they are necessary to duplicate the problem: (

Sorry for the Hotfile link. I don’t have access to my FTP at the moment. So you’ll have to type in a captcha and wait 15 seconds (click "Regular Download) to get it. :-p