diff --git a/src/deh_soc.c b/src/deh_soc.c index 28b190a67..66b05db79 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -3052,7 +3052,15 @@ void readcupheader(MYFILE *f, cupheader_t *cup) } else if (fastcmp(word, "LEVELLIST")) { - cup->numlevels = 0; + while (cup->numlevels > 0) + { + cup->numlevels--; + Z_Free(cup->levellist[cup->numlevels]); + cup->levellist[cup->numlevels] = NULL; + if (cup->cachedlevels[cup->numlevels] == NEXTMAP_INVALID) + continue; + mapheaderinfo[cup->cachedlevels[cup->numlevels]]->cup = NULL; + } tmp = strtok(word2,","); do { @@ -3069,11 +3077,13 @@ void readcupheader(MYFILE *f, cupheader_t *cup) } else if (fastcmp(word, "BONUSGAME")) { + Z_Free(cup->levellist[CUPCACHE_BONUS]); cup->levellist[CUPCACHE_BONUS] = Z_StrDup(word2); cup->cachedlevels[CUPCACHE_BONUS] = NEXTMAP_INVALID; } else if (fastcmp(word, "SPECIALSTAGE")) { + Z_Free(cup->levellist[CUPCACHE_SPECIAL]); cup->levellist[CUPCACHE_SPECIAL] = Z_StrDup(word2); cup->cachedlevels[CUPCACHE_SPECIAL] = NEXTMAP_INVALID; } diff --git a/src/p_setup.c b/src/p_setup.c index 72c3a0300..55e86232e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4487,17 +4487,20 @@ UINT8 P_InitMapData(INT32 numexistingmapheaders) cupheader_t *cup = kartcupheaders; INT32 j; - mapheaderinfo[i]->cup = NULL; - while (cup) { for (j = 0; j < CUPCACHE_MAX; j++) { + // No level in this slot? + if (!cup->levellist[j]) + continue; + // Already discovered? if (cup->cachedlevels[j] != NEXTMAP_INVALID) continue; - if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0) + // Not your name? + if (strcasecmp(cup->levellist[j], name) != 0) continue; // Only panic about back-reference for non-bonus material.