From e892cc1d4b7fcfa5abe9359f7506ca97e501504c Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 1 Feb 2024 18:57:55 +0100 Subject: [PATCH 1/2] 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 be0c7ba62..faa5372f2 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1631,7 +1631,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; side = &sides[newline->sidenum[0]]; do_texture_skew = newline->flags & ML_SKEWTD; @@ -1785,7 +1785,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; side = &sides[newline->sidenum[0]]; } diff --git a/src/r_segs.c b/src/r_segs.c index 9340ca50c..b43f5e714 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -571,7 +571,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); line_t *newline = pfloor->master->frontsector->lines[0] + linenum; sidedef = &sides[newline->sidenum[0]]; do_texture_skew = newline->flags & ML_SKEWTD; From afa9b324080789d503fb4f39e6e210e95729be11 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 1 Feb 2024 19:13:13 +0100 Subject: [PATCH 2/2] compiler complains --- 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 faa5372f2..8a1ad4f69 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1631,7 +1631,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min(gl_curline->linedef-gl_backsector->lines[0], rover->master->frontsector->linecount); + size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; side = &sides[newline->sidenum[0]]; do_texture_skew = newline->flags & ML_SKEWTD; @@ -1785,7 +1785,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->master->flags & ML_TFERLINE) { - size_t linenum = min(gl_curline->linedef-gl_backsector->lines[0], rover->master->frontsector->linecount); + size_t linenum = min((size_t)(gl_curline->linedef-gl_backsector->lines[0]), rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; side = &sides[newline->sidenum[0]]; } diff --git a/src/r_segs.c b/src/r_segs.c index b43f5e714..326b406f7 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -571,7 +571,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->master->flags & ML_TFERLINE) { - size_t linenum = min(curline->linedef-backsector->lines[0], pfloor->master->frontsector->linecount); + size_t linenum = min((size_t)(curline->linedef-backsector->lines[0]), pfloor->master->frontsector->linecount); line_t *newline = pfloor->master->frontsector->lines[0] + linenum; sidedef = &sides[newline->sidenum[0]]; do_texture_skew = newline->flags & ML_SKEWTD;