From b0425f14ed3c7c4788c5cc8f33df19bb8a6ef53d Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 4 Oct 2023 00:12:10 +0000 Subject: [PATCH] Merge branch 'precip-height-random-crash' into 'master' Conditionally randomize precip height Closes #528 See merge request KartKrew/Kart!1536 --- src/p_mobj.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 05589c11c..497783c2c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10625,6 +10625,9 @@ static void P_SpawnPrecipitationAt(fixed_t basex, fixed_t basey) for (j = 0; j < numparticles; j++) { + INT32 floorz; + INT32 ceilingz; + rainmo = P_SpawnPrecipMobj(x, y, z, type); if (randomstates > 0) @@ -10643,8 +10646,19 @@ static void P_SpawnPrecipitationAt(fixed_t basex, fixed_t basey) } } - // Randomly assign a height, now that floorz is set. - rainmo->z = M_RandomRange(rainmo->floorz >> FRACBITS, rainmo->ceilingz >> FRACBITS) << FRACBITS; + floorz = rainmo->floorz >> FRACBITS; + ceilingz = rainmo->ceilingz >> FRACBITS; + + if (floorz < ceilingz) + { + // Randomly assign a height, now that floorz is set. + rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; + } + else + { + // ...except if the floor is above the ceiling. + rainmo->z = ceilingz << FRACBITS; + } } } }