diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 602775168..6b7ff51e0 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -763,14 +763,27 @@ void setWallSectors() i++; } - for (unsigned i = 1; i < wall.Size() - 1; i++) + // + for (unsigned ii = 1; ii < wall.Size() - 1; ii++) { // two maps in RRRA have this error. Delete one of those 2 walls. - if (wall[i].point2 == wall[i + 1].point2) + if (wall[ii].point2 == wall[ii + 1].point2) { - wall[i].nextwall = -1; - wall[i].nextsector = -1; - wall[i].point2 = i; + auto w1 = wall[ii].lastWall(false); + auto w2 = wall[ii + 1].lastWall(false); + // Neutralize the bad one of the two walls. + if (w1 == nullptr) + { + wall[ii].nextwall = -1; + wall[ii].nextsector = -1; + wall[ii].point2 = ii; + } + else if (w2 == nullptr) + { + wall[ii+1].nextwall = -1; + wall[ii+1].nextsector = -1; + wall[ii+1].point2 = ii; + } } } diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 5a7b915c8..c695b069b 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -391,7 +391,7 @@ struct walltype sectortype* nextSector() const; sectortype* sectorp() const; walltype* nextWall() const; - walltype* lastWall() const; + walltype* lastWall(bool fast = true) const; walltype* point2Wall() const; vec2_t delta() const { return point2Wall()->pos - pos; } vec2_t center() const { return(point2Wall()->pos + pos) / 2; } @@ -671,10 +671,10 @@ inline sectortype* walltype::sectorp() const return &::sector[sector]; // cannot be -1 in a proper map. } -inline walltype* walltype::lastWall() const +inline walltype* walltype::lastWall(bool fast) const { int index = wall.IndexOf(this); - if (index > 0 && wall[index - 1].point2 == index) return &wall[index - 1]; + if (fast && index > 0 && wall[index - 1].point2 == index) return &wall[index - 1]; int check = index; for (int i = 0; i < 16384; i++) // don't run endlessly in case of malformed sectors.