Skip to content

Commit

Permalink
Fixed bug 1360 - fluidsynth backend segfaults sdl-mixer
Browse files Browse the repository at this point in the history
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 5423568
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion SDL_mixer.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions fluidsynth.c
Expand Up @@ -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));

Expand Down
47 changes: 26 additions & 21 deletions music_flac.c
Expand Up @@ -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 */
Expand All @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions music_ogg.c
Expand Up @@ -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;
Expand All @@ -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 ) {
Expand Down

0 comments on commit 5423568

Please sign in to comment.