Malloc problems with SDL_mixer under OS X [2]

I finally got the time to track down the line of code which causes the
segfault when switching MIDI songs. It’s "CloseComponent(gTunePlayer)"
in native_midi_freesong() in native_midi_mac.c. This is a QuickTime
function call, so this is as deep as I can debug. I have no idea why
this causes segmentation faults, neither why it seems to happen only on
my machine…

Lex

Lex wrote:> I have a weird problem with SDL_mixer. I’m working on a port of Rise Of

The Triad for Mac OS X, and the game currently crashes often when
switching MIDI songs. The crash occurs when calling Mix_FreeMusic. It
only occurs after playing a few songs. After about 3 to 5 songs, malloc
errors start to show up, and after a few more songs, a segfault occurs.
I wrote a very basic program which just loads and plays songs in the
same way, and it has exactly the same behavior. It’s at the bottom of
this post. Some songs from the game can be found at
http://www.student.kuleuven.ac.be/~m9608615/rott-songs.sit

If you want to download the current version of the ROTT source code, you
can get it at
http://www.student.kuleuven.ac.be/~m9608615/rott-1.0.sit
Or you can get the compiled binary at
http://www.student.kuleuven.ac.be/~m9608615/rott-songs.sit
You’ll also need the ROTT game files, which can be downloaded at
http://filesingularity.timedoctor.org/download.php?realfile=1&fileid=8

The weird thing is that the guys working on SDL_mixer can’t reproduce
this problem, so it might be related to ‘external factors’. Therefore it
would be interesting if as many OS X users here could try either the
simple program below or the game itself, and report the results together
with their versions of OS X and QuickTime. To switch songs in the game
easily, type “dipstick” and “maestro” after starting a game, which will
give you a jukebox.

Alexander

----------- Example C program follows: ------------

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include “SDL.h”
#include “SDL_mixer.h”

#ifdef main

undef main

#endif

int main (int argc, const char * argv[]) {
int i, numChannels;
char fName[256];
Mix_Music *music_musicchunk = NULL;

if (Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 256) < 0)
{
    printf(SDL_GetError());
    return(1);
}
numChannels = Mix_AllocateChannels(8);
if (numChannels != 8)
{
    printf(SDL_GetError());
    Mix_CloseAudio();
    return(1);
}

for(i = 1; i < 10; i++) {
    printf("Playing song %d\n",i);
    sprintf(fName,"song%d.mid",i);
    music_musicchunk = Mix_LoadMUS(fName);
    Mix_PlayMusic(music_musicchunk, 0);
    sleep(5);
    if ( (Mix_PlayingMusic()) || (Mix_PausedMusic()) )
        Mix_HaltMusic();
    Mix_FreeMusic(music_musicchunk); // This is where it crashes!
    music_musicchunk = NULL;
}
printf("Played all songs without crashing!\n");

return 0;

}