Skip to content
Permalink
Browse files

Fixed bug 1360 - fluidsynth backend segfaults sdl-mixer

We need to initialize fluidsynth!
Also cleaned up the other music initialization so they're consistent.
  • Loading branch information
slouken committed Jan 4, 2012
1 parent c16d0ce commit 542356825590c07b72cfc9094669fa9796a48fd0
Showing with 38 additions and 28 deletions.
  1. +1 −1 SDL_mixer.h
  2. +4 −0 fluidsynth.c
  3. +26 −21 music_flac.c
  4. +7 −6 music_ogg.c
@@ -70,7 +70,7 @@ typedef enum
MIX_INIT_MOD = 0x00000002,
MIX_INIT_MP3 = 0x00000004,
MIX_INIT_OGG = 0x00000008,
MIX_INIT_FLUIDSYNTH = 0x00000016
MIX_INIT_FLUIDSYNTH = 0x00000010
} MIX_InitFlags;

/* Loads dynamic libraries and prepares them for use. Flags should be
@@ -71,6 +71,10 @@ static FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynth
FluidSynthMidiSong *song;
fluid_settings_t *settings = NULL;

if (!Mix_Init(MIX_INIT_FLUIDSYNTH)) {
return NULL;
}

if ((song = malloc(sizeof(FluidSynthMidiSong)))) {
memset(song, 0, sizeof(FluidSynthMidiSong));

@@ -306,6 +306,13 @@ FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw)
int init_stage = 0;
int was_error = 1;

if (!Mix_Init(MIX_INIT_FLAC)) {
if (freerw) {
SDL_RWclose(rw);
}
return NULL;
}

music = (FLAC_music *)malloc ( sizeof (*music));
if (music) {
/* Initialize the music structure */
@@ -323,35 +330,33 @@ FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw)
music->flac_data.data_len = 0;
music->flac_data.data_read = 0;

if (Mix_Init(MIX_INIT_FLAC)) {
init_stage++; // stage 1!
init_stage++; // stage 1!

music->flac_decoder = flac.FLAC__stream_decoder_new ();
music->flac_decoder = flac.FLAC__stream_decoder_new ();

if (music->flac_decoder != NULL) {
init_stage++; // stage 2!
if (music->flac_decoder != NULL) {
init_stage++; // stage 2!

if (flac.FLAC__stream_decoder_init_stream(
music->flac_decoder,
flac_read_music_cb, flac_seek_music_cb,
flac_tell_music_cb, flac_length_music_cb,
flac_eof_music_cb, flac_write_music_cb,
flac_metadata_music_cb, flac_error_music_cb,
music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
init_stage++; // stage 3!
if (flac.FLAC__stream_decoder_init_stream(
music->flac_decoder,
flac_read_music_cb, flac_seek_music_cb,
flac_tell_music_cb, flac_length_music_cb,
flac_eof_music_cb, flac_write_music_cb,
flac_metadata_music_cb, flac_error_music_cb,
music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
init_stage++; // stage 3!

if (flac.FLAC__stream_decoder_process_until_end_of_metadata
(music->flac_decoder)) {
was_error = 0;
} else {
SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
}
if (flac.FLAC__stream_decoder_process_until_end_of_metadata
(music->flac_decoder)) {
was_error = 0;
} else {
SDL_SetError("FLAC__stream_decoder_init_stream() failed");
SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
}
} else {
SDL_SetError("FLAC__stream_decoder_new() failed");
SDL_SetError("FLAC__stream_decoder_init_stream() failed");
}
} else {
SDL_SetError("FLAC__stream_decoder_new() failed");
}

if (was_error) {
@@ -72,6 +72,13 @@ OGG_music *OGG_new_RW(SDL_RWops *rw, int freerw)
OGG_music *music;
ov_callbacks callbacks;

if ( !Mix_Init(MIX_INIT_OGG) ) {
if ( freerw ) {
SDL_RWclose(rw);
}
return(NULL);
}

SDL_memset(&callbacks, 0, sizeof(callbacks));
callbacks.read_func = sdl_read_func;
callbacks.seek_func = sdl_seek_func;
@@ -87,12 +94,6 @@ OGG_music *OGG_new_RW(SDL_RWops *rw, int freerw)
OGG_setvolume(music, MIX_MAX_VOLUME);
music->section = -1;

if ( !Mix_Init(MIX_INIT_OGG) ) {
if ( freerw ) {
SDL_RWclose(rw);
}
return(NULL);
}
if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
free(music);
if ( freerw ) {

0 comments on commit 5423568

Please sign in to comment.