From a05df40a6e9add33da5b50825a2eea78113e7972 Mon Sep 17 00:00:00 2001 From: drfrag Date: Fri, 29 May 2020 22:54:07 +0200 Subject: [PATCH] - Fixed crash on maps with out of range sidedef and sector numbers, adapted from PRBoom. # Conflicts: # src/p_setup.cpp --- src/p_setup.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 0e3400cb9..43333dd16 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1742,13 +1742,6 @@ void P_LoadLineDefs (MapData * map) } else { - // patch missing first sides instead of crashing out. - // Visual glitches are better than not being able to play. - if (LittleShort(mld->sidenum[0]) == NO_INDEX) - { - Printf("Line %d has no first side.\n", i); - mld->sidenum[0] = 0; - } sidecount++; if (LittleShort(mld->sidenum[1]) != NO_INDEX) sidecount++; @@ -1787,6 +1780,22 @@ void P_LoadLineDefs (MapData * map) ProcessEDLinedef(ld, mld->tag); } #endif + // cph 2006/09/30 - fix sidedef errors right away. + for (int j=0; j < 2; j++) + { + if (LittleShort(mld->sidenum[j]) != NO_INDEX && mld->sidenum[j] >= level.sides.Size()) + { + mld->sidenum[j] = 0; // dummy sidedef + Printf("Linedef %d has a bad sidedef\n", i); + } + } + // patch missing first sides instead of crashing out. + // Visual glitches are better than not being able to play. + if (LittleShort(mld->sidenum[0]) == NO_INDEX) + { + Printf("Line %d has no first side.\n", i); + mld->sidenum[0] = 0; + } ld->v1 = &level.vertexes[LittleShort(mld->v1)]; ld->v2 = &level.vertexes[LittleShort(mld->v2)]; @@ -2259,11 +2268,11 @@ void P_LoadSideDefs2 (MapData *map, FMissingTextureTracker &missingtex) // killough 4/4/98: allow sidedef texture names to be overloaded // killough 4/11/98: refined to allow colormaps to work as wall // textures if invalid as colormaps but valid as textures. - + // cph 2006/09/30 - catch out-of-range sector numbers; use sector 0 instead if ((unsigned)LittleShort(msd->sector)>=level.sectors.Size()) { Printf (PRINT_HIGH, "Sidedef %d has a bad sector\n", i); - sd->sector = sec = NULL; + sd->sector = sec = &level.sectors[0]; } else {