From 62fa60e39952974ac479e9dc3a88ee7f5da89c04 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 25 Apr 2024 17:08:02 +0200 Subject: [PATCH] fix rare precip crash --- 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 94226face..c8c9a26b2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10146,6 +10146,9 @@ void P_SpawnPrecipitation(void) //for (j = 0; j < cv_precipdensity.value; ++j) -- density is 1 for kart always { + INT32 floorz; + INT32 ceilingz; + x = ((cv_lessprecip.value ? basex*1.5 : basex) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); y = ((cv_lessprecip.value ? basey*1.5 : basey) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); @@ -10179,8 +10182,19 @@ void P_SpawnPrecipitation(void) else // everything else. rainmo = P_SpawnRainMobj(x, y, height, MT_RAIN); - // Randomly assign a height, now that floorz is set. - rainmo->z = M_RandomRange(rainmo->floorz>>FRACBITS, rainmo->ceilingz>>FRACBITS)<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; + } } }