diff --git a/src/deh_soc.c b/src/deh_soc.c index 6e4eac3ee..e2674bcd5 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -1175,6 +1175,7 @@ void readlevelheader(MYFILE *f, char * name) sizeof(mapheaderinfo[num]->musname[j]), va("Level header %d: music", num)); j += 1; } while ((tmp = strtok(NULL,",")) != NULL); + mapheaderinfo[num]->musname_size = j; } } else if (fastcmp(word, "MUSICSLOT")) diff --git a/src/doomstat.h b/src/doomstat.h index 37bab32ea..e72d96705 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -413,6 +413,7 @@ struct mapheader_t char musname[3][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music. UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore. UINT32 muspos; ///< Music position to jump to. + UNIT8 musname_size; ///< Number of music tracks defined // Sky information UINT8 weather; ///< See preciptype_t diff --git a/src/p_setup.c b/src/p_setup.c index 6184be712..af57b7a32 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -394,6 +394,7 @@ static void P_ClearSingleMapHeaderInfo(INT16 num) } mapheaderinfo[num]->mustrack = 0; mapheaderinfo[num]->muspos = 0; + mapheaderinfo[num]->musname_size = 0; mapheaderinfo[num]->weather = PRECIP_NONE; snprintf(mapheaderinfo[num]->skytexture, 5, "SKY1"); mapheaderinfo[num]->skytexture[4] = 0; diff --git a/src/s_sound.c b/src/s_sound.c index f5124dbcd..536601200 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2432,8 +2432,8 @@ void S_StartEx(boolean reset) if (mapmusflags & MUSIC_RELOADRESET) { - UINT32 i = P_RandomKey(PR_MUSICSELECT, 3); - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[i], 7); + UINT32 t = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size); + strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[t], 7); mapmusname[6] = 0; mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusposition = mapheaderinfo[gamemap-1]->muspos;