From d04603da1a3d2c1f49a272f5ffdfd5ff4b45cea9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Feb 2026 18:25:03 +0100 Subject: [PATCH] r_plane: fix visplane hashing overflowing shift into "int" to prevent super large values during multiply --- src/r_plane.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 78375b8b6..05c4d943a 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -57,8 +57,11 @@ visffloor_t visffloor[MAXFFLOORS] = {}; INT32 numffloors = 0; //SoM: 3/23/2000: Boom visplane hashing routine. -#define visplane_hash(picnum,lightlevel,height) \ - ((unsigned)((picnum)*3+(lightlevel)+(height)*7) & VISPLANEHASHMASK) +constexpr unsigned int visplane_hash(const unsigned int picnum, const unsigned int lightlevel, + const unsigned int height) +{ + return ((picnum * 3) + lightlevel + (height * 7)) & VISPLANEHASHMASK; +} // // Clip values are the solid pixel bounding the range. @@ -451,7 +454,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, } } - hash = visplane_hash(picnum, lightlevel, height); + hash = visplane_hash(picnum, lightlevel, height >> FRACBITS); for (check = visplanes[hash]; check; check = check->next) { @@ -562,7 +565,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) } else { - unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height); + unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height >> FRACBITS); new_pl = new_visplane(hash); }