From 553dfb35440c9097c3065aa73f35015ff5f6a3bf Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Thu, 24 Oct 2019 05:47:15 +0000 Subject: [PATCH] Prefer early return on error in sound and MIDI init functions git-svn-id: https://svn.eduke32.com/eduke32@8259 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/duke3d/src/sounds.cpp # source/duke3d/src/sounds_mapster32.cpp # source/sw/src/sounds.cpp --- source/duke3d/src/sounds.cpp | 12 +++++------- source/sw/src/sounds.cpp | 26 ++++++++++++-------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index ef75f2b3b..a176c5f81 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -115,10 +115,13 @@ void S_MusicStartup(void) { initprintf("Initializing MIDI driver... "); - if (MUSIC_Init(ud.config.MusicDevice) == MUSIC_Ok || MUSIC_Init(0) == MUSIC_Ok || MUSIC_Init(1) == MUSIC_Ok) + if (MUSIC_Init(ud.config.MusicDevice) != MUSIC_Ok && MUSIC_Init(0) != MUSIC_Ok && MUSIC_Init(1) != MUSIC_Ok) { - MUSIC_SetVolume(mus_volume); + initprintf("S_MusicStartup(): failed initializing\n"); + return; + } + MUSIC_SetVolume(mus_volume); auto const fil = kopen4load("d3dtimbr.tmb", 0); if (fil != buildvfs_kfd_invalid) @@ -130,11 +133,6 @@ void S_MusicStartup(void) Xfree(tmb); kclose(fil); } - - return; - } - - initprintf("S_MusicStartup(): failed initializing\n"); } void S_MusicShutdown(void) diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index c22406f71..7c6a5a509 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -1133,17 +1133,16 @@ SoundStartup(void) status = FX_Init(NumVoices, NumChannels, MixRate, initdata); - if (status == FX_Ok) - { - FxInitialized = TRUE; - snd_fxvolume.Callback(); - snd_reversestereo.Callback(); - } if (status != FX_Ok) { buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error)); + return; } + FxInitialized = TRUE; + snd_fxvolume.Callback(); + snd_reversestereo.Callback(); + FX_SetCallBack(SoundCallBack); } @@ -1201,17 +1200,16 @@ void MusicStartup(void) buildprintf("Initializing MIDI driver... "); - if (MUSIC_Init(MusicDevice) == MUSIC_Ok || MUSIC_Init(0) == MUSIC_Ok || MUSIC_Init(1) == MUSIC_Ok) + if (MUSIC_Init(MusicDevice) != MUSIC_Ok && MUSIC_Init(0) != MUSIC_Ok && MUSIC_Init(1) != MUSIC_Ok) { - MusicInitialized = TRUE; - MUSIC_SetVolume(mus_volume); - } - else - { - buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_ErrorCode)); + buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_Error)); mus_enabled = FALSE; + return; } + MusicInitialized = TRUE; + MUSIC_SetVolume(gs.MusicVolume); + #if 0 if (MusicInitialized) loadtmb(); @@ -1241,7 +1239,7 @@ MusicShutdown(void) status = MUSIC_Shutdown(); if (status != MUSIC_Ok) { - buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_ErrorCode)); + buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_Error)); } }