diff --git a/src/p_setup.c b/src/p_setup.c
index 609db7c4f62414e92cdf7b2816bfc31ae24f54de..89e9fffae93ec82ff010904440385bd809a028e0 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -1375,6 +1375,8 @@ static void P_LoadSidedefs(UINT8 *data)
 		sd->scalex_top = sd->scalex_mid = sd->scalex_bottom = FRACUNIT;
 		sd->scaley_top = sd->scaley_mid = sd->scaley_bottom = FRACUNIT;
 
+		sd->flags = 0;
+
 		P_InitSideEdges(sd);
 
 		P_SetSidedefSector(i, (UINT16)SHORT(msd->sector));
@@ -2690,6 +2692,8 @@ static void P_WriteTextmap(void)
 			fprintf(f, "midpeg = true;\n");
 		if (wlines[i].flags & ML_MIDSOLID)
 			fprintf(f, "midsolid = true;\n");
+		if (wlines[i].flags & ML_CLIPMIDTEX)
+			fprintf(f, "clipmidtex = true;\n");
 		if (wlines[i].flags & ML_WRAPMIDTEX)
 			fprintf(f, "wrapmidtex = true;\n");
 		if (wlines[i].flags & ML_NONET)
@@ -3155,6 +3159,7 @@ static void P_LoadTextmap(void)
 		sd->bottomtexture = R_TextureNumForName("-");
 		sd->sector = NULL;
 		sd->repeatcnt = 0;
+		sd->flags = 0;
 
 		P_InitSideEdges(sd);
 
diff --git a/src/r_defs.h b/src/r_defs.h
index 75c2c7aea427a534f88f0c50ecba22f2268564cc..074db8f12bd8f3ad90a801f931f31c7e6914644c 100644
--- a/src/r_defs.h
+++ b/src/r_defs.h
@@ -631,10 +631,10 @@ typedef struct line_s
 // Don't make available to Lua or I will find where you live
 typedef enum
 {
-	SIDEFLAG_CLIP_MIDTEX     = 1<<4, // Like the line counterpart, but only for this side.
-	SIDEFLAG_WRAP_MIDTEX     = 1<<5, // Like the line counterpart, but only for this side.
+	SIDEFLAG_CLIP_MIDTEX     = 1 << 0, // Like the line counterpart, but only for this side.
+	SIDEFLAG_WRAP_MIDTEX     = 1 << 1, // Like the line counterpart, but only for this side.
 
-	SIDEFLAG_HASEDGETEXTURES = 1<<13 // Side has an edge texture applied (so that the renderer can quickly skip all relevant code)
+	SIDEFLAG_HASEDGETEXTURES = 1 << 2 // Side has an edge texture applied (so that the renderer can quickly skip all relevant code)
 } sideflags_t;
 
 enum
@@ -669,6 +669,7 @@ typedef struct side_s
 	fixed_t scalex_top, scalex_mid, scalex_bottom;
 	fixed_t scaley_top, scaley_mid, scaley_bottom;
 
+	// Rendering-related flags
 	UINT16 flags;
 
 	// Texture indices.
diff --git a/src/r_segs.c b/src/r_segs.c
index f25fc4db503772ad3189368feae3a6daccdd652a..de4628b300366a900fc4ea8d54356abf76e626ce 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -420,14 +420,13 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
 	rw_scalestep = scalestep;
 	spryscale = scale1 + (x1 - ds->x1)*rw_scalestep;
 
-	// Texture must be cached before setting colfunc_2s,
-	// otherwise texture[texnum]->holes may be false when it shouldn't be
+	// Texture must be cached
 	R_CheckTextureCache(texnum);
 
 	if (vertflip) // vertically flipped?
 		colfunc_2s = R_DrawFlippedMaskedColumn;
 	else
-		colfunc_2s = R_DrawMaskedColumn; // render the usual 2sided single-patch packed texture
+		colfunc_2s = R_DrawMaskedColumn;
 
 	lengthcol = textures[texnum]->height;
 
@@ -564,7 +563,9 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
 				left_bottom += bottom_step;
 			}
 
-			sprtopscreen = centeryfrac - FixedMul(texture_top, spryscale);
+			// NB: sprtopscreen needs to start where dc_texturemid does, so that R_DrawMaskedColumn works correctly.
+			// windowtop however is set so that the column gets clipped properly.
+			sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale);
 			realbot = centeryfrac - FixedMul(texture_bottom, spryscale);
 
 			if (do_overlay_column)
@@ -573,7 +574,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
 			// set wall bounds if necessary
 			if (dc_numlights || clipmidtex)
 			{
-				windowtop = sprtopscreen;
+				windowtop = centeryfrac - FixedMul(texture_top, spryscale);
 				windowbottom = realbot;
 			}
 
@@ -710,14 +711,13 @@ static void R_RenderExtraTexture(unsigned which, INT32 x1, INT32 x2, INT32 repea
 	rw_scalestep = scalestep;
 	spryscale = scale1 + (x1 - ds->x1)*rw_scalestep;
 
-	// Texture must be cached before setting colfunc_2s,
-	// otherwise texture[texnum]->holes may be false when it shouldn't be
+	// Texture must be cached
 	R_CheckTextureCache(texnum);
 
 	if (vertflip) // vertically flipped?
 		colfunc_2s = R_DrawFlippedMaskedColumn;
 	else
-		colfunc_2s = R_DrawMaskedColumn; // render the usual 2sided single-patch packed texture
+		colfunc_2s = R_DrawMaskedColumn;
 
 	lengthcol = textures[texnum]->height;