diff --git a/src/portal.cpp b/src/portal.cpp index 6ec1c6c1d..a6446a82b 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -1086,6 +1086,26 @@ void P_CreateLinkedPortals() sectors[i].lines[j]->flags |= ML_PORTALCONNECT; } } + if (sectors[i].PortalIsLinked(sector_t::ceiling) && sectors[i].PortalIsLinked(sector_t::floor)) + { + fixed_t cz = sectors[i].SkyBoxes[sector_t::ceiling]->threshold; + fixed_t fz = sectors[i].SkyBoxes[sector_t::floor]->threshold; + if (cz < fz) + { + // This is a fatal condition. We have to remove one of the two portals. Choose the one that doesn't match the current plane + Printf("Error in sector %d: Ceiling portal at z=%d is below floor portal at z=%d\n", i, cz, fz); + fixed_t cp = sectors[i].ceilingplane.Zat0(); + fixed_t fp = sectors[i].ceilingplane.Zat0(); + if (cp < fp || fz == fp) + { + sectors[i].SkyBoxes[sector_t::ceiling] = NULL; + } + else + { + sectors[i].SkyBoxes[sector_t::floor] = NULL; + } + } + } } //BuildBlockmap(); }