From 5fda1b297f77705d16a73d7db8c73be18ce6f06a Mon Sep 17 00:00:00 2001 From: Eidolon Date: Tue, 12 Apr 2022 22:39:40 -0500 Subject: [PATCH] Delete interpolators associated with thinkers --- src/p_tick.c | 1 + src/r_fps.c | 20 ++++++++++++++++++++ src/r_fps.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/p_tick.c b/src/p_tick.c index c2f2b0579..e244de1c6 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -255,6 +255,7 @@ void P_RemoveThinkerDelayed(thinker_t *thinker) * thinker->prev->next = thinker->next */ (next->prev = currentthinker = thinker->prev)->next = next; + R_DestroyLevelInterpolators(thinker); Z_Free(thinker); } diff --git a/src/r_fps.c b/src/r_fps.c index d2a31a6e6..559520c5d 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -474,3 +474,23 @@ void R_RestoreLevelInterpolators(void) } } } + +void R_DestroyLevelInterpolators(thinker_t *thinker) +{ + size_t i; + + for (i = 0; i < levelinterpolators_len; i++) + { + levelinterpolator_t *interp = levelinterpolators[i]; + + if (interp->thinker == thinker) + { + // Swap the tail of the level interpolators to this spot + levelinterpolators[i] = levelinterpolators[levelinterpolators_len - 1]; + levelinterpolators_len -= 1; + + Z_Free(interp); + i -= 1; + } + } +} diff --git a/src/r_fps.h b/src/r_fps.h index af9baa962..0e10cf5e6 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -119,5 +119,7 @@ void R_ClearLevelInterpolatorState(thinker_t *thinker); void R_ApplyLevelInterpolators(fixed_t frac); // Restore level interpolators to the real game state void R_RestoreLevelInterpolators(void); +// Destroy interpolators associated with a thinker +void R_DestroyLevelInterpolators(thinker_t *thinker); #endif