From 55b4458001b2ffe76774ff07a11b56ebf1f70de9 Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Tue, 22 Aug 2023 13:34:09 -0300
Subject: [PATCH] Fix a possible crash in R_RenderMaskedSegRange
 R_AllocTextureColumnTables wasn't checking if the tables were never
 allocated, making the renderer later attempt to render midtextures for
 drawsegs that don't contain actual midtextures.

---
 src/r_segs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/r_segs.c b/src/r_segs.c
index 9ee3bcfec..9af83f0c7 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -1487,6 +1487,9 @@ static void R_AllocClippingTables(size_t range)
 	openings = Z_Realloc(openings, numopenings * sizeof (*openings), PU_STATIC, NULL);
 	lastopening = openings + pos;
 
+	if (oldopenings == NULL)
+		return;
+
 	// borrowed fix from *cough* zdoom *cough*
 	// [RH] We also need to adjust the openings pointers that
 	//    were already stored in drawsegs.
@@ -1519,6 +1522,9 @@ static void R_AllocTextureColumnTables(size_t range)
 	texturecolumntable = Z_Realloc(texturecolumntable, texturecolumntablesize * sizeof (*texturecolumntable), PU_STATIC, NULL);
 	curtexturecolumntable = texturecolumntable + pos;
 
+	if (oldtable == NULL)
+		return;
+
 	for (drawseg_t *ds = drawsegs; ds < ds_p; ds++)
 	{
 		// Check if it's in range of the tables
-- 
GitLab