From 67bac0aa883822bb593ba4618ef0ad60ee5d3b91 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 19 Nov 2026 14:43:54 +0100 Subject: [PATCH] fix zero division in HWR_SplitSprite same fix as HWR_SplitWall this may throw nan texture uv coords into gl which may be uncool --- src/hardware/hw_main.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e0c4a0bbc..6efdd7271 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1280,7 +1280,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, // To avoid division by zero, which would result in a NaN, we check if the vertical difference // between the two vertices is not zero. if (std::fpclassify(diff) == FP_ZERO) - pegmul = 0.0; + pegmul = 0.0f; else pegmul = (pegb - pegt) / diff; @@ -1292,7 +1292,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, endpegb = wallVerts[1].t; if (std::fpclassify(diff) == FP_ZERO) - endpegmul = 0.0; + endpegmul = 0.0f; else endpegmul = (endpegb - endpegt) / diff; @@ -3856,7 +3856,16 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) realbot = bot = baseWallVerts[0].y; towtop = baseWallVerts[3].t; towbot = baseWallVerts[0].t; - towmult = (towbot - towtop) / (top - bot); + + float diff = (top - bot); + + // If both heights of a side lay on the same position, then this sprite is a triangle. + // To avoid division by zero, which would result in a NaN, we check if the vertical difference + // between the two vertices is not zero. + if (std::fpclassify(diff) == FP_ZERO) + towmult = 0.0f; + else + towmult = (towbot - towtop) / diff; endrealtop = endtop = baseWallVerts[2].y; endrealbot = baseWallVerts[1].y; @@ -4027,7 +4036,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) if ((endtop <= endrealbot) && (top <= realbot)) return; - // If we're ever down here, somehow the above loop hasn't draw all the light levels of sprite + // If we're ever down here, somehow the above loop hasn't drawn all the light levels of sprite wallVerts[3].t = towtop + ((realtop - top) * towmult); wallVerts[2].t = towtop + ((endrealtop - endtop) * towmult); wallVerts[0].t = towtop + ((realtop - bot) * towmult);