From 8e6e122c05cf56c37a809e64dfaf5c213ccf185e Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 8 Feb 2024 18:37:01 -0800 Subject: [PATCH] R_AddPrecipitationSprites: fix use of th after freed R_ProjectPrecipitationSprite may free th --- src/r_things.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index bd480dfc8..48ce29bc9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2567,7 +2567,7 @@ void R_AddPrecipitationSprites(void) const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; INT32 xl, xh, yl, yh, bx, by; - precipmobj_t *th; + precipmobj_t *th, *next; // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off if (drawdist == 0) @@ -2581,8 +2581,11 @@ void R_AddPrecipitationSprites(void) { for (by = yl; by <= yh; by++) { - for (th = precipblocklinks[(by * bmapwidth) + bx]; th; th = th->bnext) + for (th = precipblocklinks[(by * bmapwidth) + bx]; th; th = next) { + // Store this beforehand because R_ProjectPrecipitionSprite may free th (see P_PrecipThinker) + next = th->bnext; + if (R_PrecipThingVisible(th)) { R_ProjectPrecipitationSprite(th);