mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-16 01:11:44 +00:00
sdlmusic: Implement graceful playback failure
git-svn-id: https://svn.eduke32.com/eduke32@6890 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
03f2cdd9b3
commit
b5caf1cd1e
1 changed files with 23 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue