From 8c539539dfa23837f99ffc1dce4425807933c4f0 Mon Sep 17 00:00:00 2001 From: drfrag Date: Fri, 29 May 2020 13:01:34 +0200 Subject: [PATCH] - Fixed crash on maps with out of range sidedef and sector numbers, adapted from PRBoom. --- src/maploader/maploader.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 234245556..961159590 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -1702,13 +1702,6 @@ void MapLoader::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++; @@ -1747,6 +1740,22 @@ void MapLoader::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)]; @@ -2180,11 +2189,11 @@ void MapLoader::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 = nullptr; + sd->sector = sec = &Level->sectors[0]; } else {