From 9fe4f135393309f195061be4e599a5f587508931 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 1 Feb 2024 18:57:55 +0100 Subject: [PATCH] Fix FOFs with transferline flag and many linedefs randomly crashing linenum could go out of bounds if you use more than 4 linedefs for such setup, hence making the game unable to retrieve textures and therefore crashing the games sometimes many thanks to indev for helping me figuring this one out c: --- src/hardware/hw_main.c | 4 ++-- src/r_segs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9aec64fad..761190eb1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1667,7 +1667,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = gl_curline->linedef-gl_backsector->lines[0]; + size_t linenum = min(gl_curline->linedef-gl_backsector->lines[0], rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -1827,7 +1827,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = gl_curline->linedef-gl_backsector->lines[0]; + size_t linenum = min(gl_curline->linedef-gl_backsector->lines[0], rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } diff --git a/src/r_segs.c b/src/r_segs.c index 7f190ea3f..d2f9db9a0 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -653,7 +653,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->master->flags & ML_TFERLINE) { - size_t linenum = curline->linedef-backsector->lines[0]; + size_t linenum = min(curline->linedef-backsector->lines[0], pfloor->master->frontsector->linecount); newline = pfloor->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); bmnum = R_GetTextureBrightmap(texnum);