diff --git a/src/s_sound.c b/src/s_sound.c index bed852d4c..b450cc0c7 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1353,6 +1353,7 @@ void S_InitSfxChannels(INT32 sfxVolume) /// ------------------------ static char music_name[7]; // up to 6-character name +static lumpnum_t music_lump; static void *music_data; static UINT16 music_flags; static boolean music_looping; @@ -1985,6 +1986,17 @@ static musicstack_t *S_GetMusicStackEntry(UINT16 status, boolean fromfirst, INT1 return NULL; } +boolean S_CheckDeletedMusic(void) +{ + if (music_lump != S_GetMusicLumpNum(music_name)) + { + S_StopMusic(); + return true; + } + + return false; +} + void S_RetainMusic(const char *mname, UINT16 mflags, boolean looping, UINT32 position, UINT16 status) { musicstack_t *mst; @@ -2150,12 +2162,12 @@ static boolean S_LoadMusic(const char *mname) // load & register it mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); - if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) { strncpy(music_name, mname, 7); music_name[6] = 0; music_data = mdata; + music_lump = mlumpnum; return true; } else @@ -2325,6 +2337,8 @@ void S_StopMusic(void) I_StopSong(); S_UnloadMusic(); // for now, stopping also means you unload the song + music_lump = LUMPERROR; + if (cv_closedcaptioning.value) { if (closedcaptions[0].s-S_sfx == sfx_None) diff --git a/src/s_sound.h b/src/s_sound.h index 60dc93897..b97e02a85 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -127,6 +127,8 @@ void S_StopSounds(void); void S_ClearSfx(void); void S_PlayMapMusic(boolean reset); +boolean S_CheckDeletedMusic(void); + // // Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum. // diff --git a/src/w_wad.c b/src/w_wad.c index 0a563f708..14e0000aa 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1259,6 +1259,9 @@ void W_UnloadWadFile(UINT16 num) W_ClearCachedData(); + if (is_important) + S_StopMusic(); + W_UnloadFile(wadfiles[num]); wadfiles[num] = NULL; @@ -1272,10 +1275,13 @@ void W_UnloadWadFile(UINT16 num) HU_LoadGraphics(); ST_LoadGraphics(); ST_ReloadSkinFaceGraphics(); - S_PlayMapMusic(true); + if (S_CheckDeletedMusic()) + S_PlayMapMusic(true); return; } + S_CheckDeletedMusic(); + D_ReloadFiles(); G_LoadGameData(clientGamedata); @@ -1286,10 +1292,9 @@ void W_UnloadWadFile(UINT16 num) void W_ClearCachedData(void) { - // Stop all sounds, stop current music + // Stop all sounds S_StopSounds(); S_ClearSfx(); - S_StopMusic(); // Unload HUD graphics ST_UnloadGraphics();