From 43a6bbd2e88874cc9783932edd213f6ecb2f6e45 Mon Sep 17 00:00:00 2001 From: Penelope Haze <110272328+out-of-phaze@users.noreply.github.com> Date: Wed, 14 Sep 2022 12:52:10 -0500 Subject: [PATCH] Fix looping timers qdeleted in their callbacks being reinserted (#69879) Fix looping timers qdeleted in their callbacks Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/controllers/subsystem/timer.dm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/controllers/subsystem/timer.dm b/code/controllers/subsystem/timer.dm index 89596a5720b..ffc232c49e8 100644 --- a/code/controllers/subsystem/timer.dm +++ b/code/controllers/subsystem/timer.dm @@ -127,7 +127,9 @@ SUBSYSTEM_DEF(timer) ctime_timer.spent = REALTIMEOFDAY callBack.InvokeAsync() - if(ctime_timer.flags & TIMER_LOOP) + if(ctime_timer.flags & TIMER_LOOP) // Re-insert valid looping client timers into the client timer list. + if (QDELETED(ctime_timer)) // Don't re-insert timers deleted inside their callbacks. + continue ctime_timer.spent = 0 ctime_timer.timeToRun = REALTIMEOFDAY + ctime_timer.wait BINARY_INSERT(ctime_timer, clienttime_timers, /datum/timedevent, ctime_timer, timeToRun, COMPARE_KEY) @@ -173,7 +175,9 @@ SUBSYSTEM_DEF(timer) callBack.InvokeAsync() last_invoke_tick = world.time - if (timer.flags & TIMER_LOOP) // Prepare looping timers to re-enter the queue + if (timer.flags & TIMER_LOOP) // Prepare valid looping timers to re-enter the queue + if(QDELETED(timer)) // If a loop is deleted in its callback, we need to avoid re-inserting it. + continue timer.spent = 0 timer.timeToRun = world.time + timer.wait timer.bucketJoin()