From 42146c5ea286f672b187c859222efbdb11546214 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.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index a9a13182f..3c2e9576f 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2843,7 +2843,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) @@ -2863,8 +2863,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);