diff --git a/src/r_segs.c b/src/r_segs.c
index 1f5477ecf5e7f0da53d8cfd602f53051b031f060..66413c58824a04dbb2110d2b55d344df65ae9917 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -2032,8 +2032,13 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 			markceiling = false;
 		}
 
+#ifdef ESLOPE
+		if ((worldhigh <= worldbottom && worldhighslope <= worldbottomslope)
+		|| (worldlow >= worldtop && worldlowslope >= worldtopslope))
+#else
 		if (backsector->ceilingheight <= frontsector->floorheight ||
 		    backsector->floorheight >= frontsector->ceilingheight)
+#endif
 		{
 			// closed door
 			markceiling = markfloor = true;