From 4e5644335a7ce4392292014bc1cc5de1476bcdcf Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 21 Jan 2020 14:55:50 -0800 Subject: [PATCH 1/3] Revert "Fix Ploadflat closing the game with "Too many flats in level" error message" This reverts commit 51c70742473d6a91753f025066a7ff7af37bd25d. --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 42a6438a0..9a270d2f3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -672,7 +672,7 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) // INT32 P_AddLevelFlatRuntime(const char *flatname) { - return Ploadflat(levelflats, flatname); + return Ploadflat(0, flatname); } // help function for $$$.sav checking From 08ba4ece8e6e7aff50417d079f95c45041989966 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 21 Jan 2020 15:11:16 -0800 Subject: [PATCH 2/3] Don't check "Too many flats in level" with P_AddLevelFlatRuntime Also moved the debug down in case anyone uses that. --- src/p_setup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 9a270d2f3..9b5b7e5c2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -585,15 +585,11 @@ Ploadflat (levelflat_t *levelflat, const char *flatname) if (strnicmp(levelflat[i].name, flatname, 8) == 0) return i; } + + if (numlevelflats >= MAXLEVELFLATS) + I_Error("Too many flats in level\n"); } -#ifndef ZDEBUG - CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); -#endif - - if (numlevelflats >= MAXLEVELFLATS) - I_Error("Too many flats in level\n"); - if (levelflat) levelflat += numlevelflats; else @@ -656,6 +652,10 @@ flatfound: levelflat->u.flat.baselumpnum = LUMPERROR; } +#ifndef ZDEBUG + CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); +#endif + return ( numlevelflats++ ); } From f906a7bcce1577d97c6c9563933140e5ac081b57 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 21 Jan 2020 16:47:47 -0800 Subject: [PATCH 3/3] Actually actually match the old behavior and check existing levelflats in P_AddLevelFlatRuntime BRUH --- src/p_setup.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 9b5b7e5c2..132684163 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -566,7 +566,7 @@ levelflat refers to an array of level flats, or NULL if we want to allocate it now. */ static INT32 -Ploadflat (levelflat_t *levelflat, const char *flatname) +Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) { #ifndef NO_PNG_LUMPS UINT8 buffer[8]; @@ -577,27 +577,26 @@ Ploadflat (levelflat_t *levelflat, const char *flatname) size_t i; - if (levelflat) + // Scan through the already found flats, return if it matches. + for (i = 0; i < numlevelflats; i++) { - // Scan through the already found flats, return if it matches. - for (i = 0; i < numlevelflats; i++) - { - if (strnicmp(levelflat[i].name, flatname, 8) == 0) - return i; - } - - if (numlevelflats >= MAXLEVELFLATS) - I_Error("Too many flats in level\n"); + if (strnicmp(levelflat[i].name, flatname, 8) == 0) + return i; } - if (levelflat) - levelflat += numlevelflats; - else + if (resize) { // allocate new flat memory levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL); levelflat = levelflats + numlevelflats; } + else + { + if (numlevelflats >= MAXLEVELFLATS) + I_Error("Too many flats in level\n"); + + levelflat += numlevelflats; + } // Store the name. strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); @@ -663,7 +662,7 @@ flatfound: // allocate an id for it, and set the levelflat (to speedup search) INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) { - return Ploadflat(levelflat, flatname); + return Ploadflat(levelflat, flatname, false); } // help function for Lua and $$$.sav reading @@ -672,7 +671,7 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) // INT32 P_AddLevelFlatRuntime(const char *flatname) { - return Ploadflat(0, flatname); + return Ploadflat(levelflats, flatname, true); } // help function for $$$.sav checking