Skip to content

Commit

Permalink
- Fixed crash on maps with out of range sidedef and sector numbers, a…
Browse files Browse the repository at this point in the history
…dapted from PRBoom.
  • Loading branch information
drfrag666 authored and coelckers committed May 29, 2020
1 parent 332dfa4 commit 8c53953
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/maploader/maploader.cpp
Expand Up @@ -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++;
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 8c53953

Please sign in to comment.