Fixed bug 1360 - fluidsynth backend segfaults sdl-mixer
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jan 2012 01:41:10 -0500
changeset 54532e5ed415a34
parent 544 117358d687fd
child 546 83de6eb0d6d2
Fixed bug 1360 - fluidsynth backend segfaults sdl-mixer

We need to initialize fluidsynth!
Also cleaned up the other music initialization so they're consistent.
SDL_mixer.h
fluidsynth.c
music_flac.c
music_ogg.c
     1.1 --- a/SDL_mixer.h	Wed Jan 04 01:09:57 2012 -0500
     1.2 +++ b/SDL_mixer.h	Wed Jan 04 01:41:10 2012 -0500
     1.3 @@ -70,7 +70,7 @@
     1.4      MIX_INIT_MOD         = 0x00000002,
     1.5      MIX_INIT_MP3         = 0x00000004,
     1.6      MIX_INIT_OGG         = 0x00000008,
     1.7 -    MIX_INIT_FLUIDSYNTH  = 0x00000016
     1.8 +    MIX_INIT_FLUIDSYNTH  = 0x00000010
     1.9  } MIX_InitFlags;
    1.10  
    1.11  /* Loads dynamic libraries and prepares them for use.  Flags should be
     2.1 --- a/fluidsynth.c	Wed Jan 04 01:09:57 2012 -0500
     2.2 +++ b/fluidsynth.c	Wed Jan 04 01:41:10 2012 -0500
     2.3 @@ -71,6 +71,10 @@
     2.4  	FluidSynthMidiSong *song;
     2.5  	fluid_settings_t *settings = NULL;
     2.6  
     2.7 +	if (!Mix_Init(MIX_INIT_FLUIDSYNTH)) {
     2.8 +		return NULL;
     2.9 +	}
    2.10 +
    2.11  	if ((song = malloc(sizeof(FluidSynthMidiSong)))) {
    2.12  		memset(song, 0, sizeof(FluidSynthMidiSong));
    2.13  
     3.1 --- a/music_flac.c	Wed Jan 04 01:09:57 2012 -0500
     3.2 +++ b/music_flac.c	Wed Jan 04 01:41:10 2012 -0500
     3.3 @@ -306,6 +306,13 @@
     3.4  	int init_stage = 0;
     3.5  	int was_error = 1;
     3.6  
     3.7 +	if (!Mix_Init(MIX_INIT_FLAC)) {
     3.8 +		if (freerw) {
     3.9 +			SDL_RWclose(rw);
    3.10 +		}
    3.11 +		return NULL;
    3.12 +	}
    3.13 +
    3.14  	music = (FLAC_music *)malloc ( sizeof (*music));
    3.15  	if (music) {
    3.16  		/* Initialize the music structure */
    3.17 @@ -323,35 +330,33 @@
    3.18  		music->flac_data.data_len = 0;
    3.19  		music->flac_data.data_read = 0;
    3.20  
    3.21 -		if (Mix_Init(MIX_INIT_FLAC)) {
    3.22 -			init_stage++; // stage 1!
    3.23 +		init_stage++; // stage 1!
    3.24  
    3.25 -			music->flac_decoder = flac.FLAC__stream_decoder_new ();
    3.26 +		music->flac_decoder = flac.FLAC__stream_decoder_new ();
    3.27  
    3.28 -			if (music->flac_decoder != NULL) {
    3.29 -				init_stage++; // stage 2!
    3.30 +		if (music->flac_decoder != NULL) {
    3.31 +			init_stage++; // stage 2!
    3.32  
    3.33 -				if (flac.FLAC__stream_decoder_init_stream(
    3.34 -							music->flac_decoder,
    3.35 -							flac_read_music_cb, flac_seek_music_cb,
    3.36 -							flac_tell_music_cb, flac_length_music_cb,
    3.37 -							flac_eof_music_cb, flac_write_music_cb,
    3.38 -							flac_metadata_music_cb, flac_error_music_cb,
    3.39 -							music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
    3.40 -					init_stage++; // stage 3!
    3.41 +			if (flac.FLAC__stream_decoder_init_stream(
    3.42 +						music->flac_decoder,
    3.43 +						flac_read_music_cb, flac_seek_music_cb,
    3.44 +						flac_tell_music_cb, flac_length_music_cb,
    3.45 +						flac_eof_music_cb, flac_write_music_cb,
    3.46 +						flac_metadata_music_cb, flac_error_music_cb,
    3.47 +						music) == FLAC__STREAM_DECODER_INIT_STATUS_OK ) {
    3.48 +				init_stage++; // stage 3!
    3.49  
    3.50 -					if (flac.FLAC__stream_decoder_process_until_end_of_metadata
    3.51 -											(music->flac_decoder)) {
    3.52 -						was_error = 0;
    3.53 -					} else {
    3.54 -						SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
    3.55 -					}
    3.56 +				if (flac.FLAC__stream_decoder_process_until_end_of_metadata
    3.57 +										(music->flac_decoder)) {
    3.58 +					was_error = 0;
    3.59  				} else {
    3.60 -					SDL_SetError("FLAC__stream_decoder_init_stream() failed");
    3.61 +					SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
    3.62  				}
    3.63  			} else {
    3.64 -				SDL_SetError("FLAC__stream_decoder_new() failed");
    3.65 +				SDL_SetError("FLAC__stream_decoder_init_stream() failed");
    3.66  			}
    3.67 +		} else {
    3.68 +			SDL_SetError("FLAC__stream_decoder_new() failed");
    3.69  		}
    3.70  
    3.71  		if (was_error) {
     4.1 --- a/music_ogg.c	Wed Jan 04 01:09:57 2012 -0500
     4.2 +++ b/music_ogg.c	Wed Jan 04 01:41:10 2012 -0500
     4.3 @@ -72,6 +72,13 @@
     4.4  	OGG_music *music;
     4.5  	ov_callbacks callbacks;
     4.6  
     4.7 +	if ( !Mix_Init(MIX_INIT_OGG) ) {
     4.8 +		if ( freerw ) {
     4.9 +			SDL_RWclose(rw);
    4.10 +		}
    4.11 +		return(NULL);
    4.12 +	}
    4.13 +
    4.14  	SDL_memset(&callbacks, 0, sizeof(callbacks));
    4.15  	callbacks.read_func = sdl_read_func;
    4.16  	callbacks.seek_func = sdl_seek_func;
    4.17 @@ -87,12 +94,6 @@
    4.18  		OGG_setvolume(music, MIX_MAX_VOLUME);
    4.19  		music->section = -1;
    4.20  
    4.21 -		if ( !Mix_Init(MIX_INIT_OGG) ) {
    4.22 -			if ( freerw ) {
    4.23 -				SDL_RWclose(rw);
    4.24 -			}
    4.25 -			return(NULL);
    4.26 -		}
    4.27  		if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
    4.28  			free(music);
    4.29  			if ( freerw ) {