diff --git a/source/duke3d/src/sdlmusic.cpp b/source/duke3d/src/sdlmusic.cpp index abe37d78f..bfb8229c2 100644 --- a/source/duke3d/src/sdlmusic.cpp +++ b/source/duke3d/src/sdlmusic.cpp @@ -359,13 +359,14 @@ int32_t MUSIC_StopSong(void) } // MUSIC_StopSong #if defined FORK_EXEC_MIDI -static void playmusic() +static int32_t playmusic() { pid_t pid = vfork(); if (pid==-1) // error { initprintf("%s: vfork: %s\n", __func__, strerror(errno)); + return MUSIC_Error; } else if (pid==0) // child { @@ -380,6 +381,8 @@ static void playmusic() { external_midi_pid = pid; } + + return MUSIC_Ok; } static void sigchld_handler(int signo) @@ -408,9 +411,6 @@ static void sigchld_handler(int signo) int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag) { // initprintf("MUSIC_PlaySong"); - // TODO: graceful failure - MUSIC_StopSong(); - if (external_midi) { FILE *fp; @@ -440,14 +440,23 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag) #if defined FORK_EXEC_MIDI external_midi_restart = loopflag; - playmusic(); + int32_t retval = playmusic(); + if (retval != MUSIC_Ok) + return retval; #else music_musicchunk = Mix_LoadMUS(external_midi_tempfn); if (!music_musicchunk) + { initprintf("Mix_LoadMUS: %s\n", Mix_GetError()); + return MUSIC_Error; + } #endif } - else initprintf("%s: fopen: %s\n", __func__, strerror(errno)); + else + { + initprintf("%s: fopen: %s\n", __func__, strerror(errno)); + return MUSIC_Error; + } } else music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem(song, songsize) @@ -456,9 +465,14 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag) #endif ); - if (music_musicchunk != NULL) - if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1) - initprintf("Mix_PlayMusic: %s\n", Mix_GetError()); + if (music_musicchunk == NULL) + return MUSIC_Error; + + if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1) + { + initprintf("Mix_PlayMusic: %s\n", Mix_GetError()); + return MUSIC_Error; + } return MUSIC_Ok; }