From 49278204d4ef15a73bfd95cc341ad054c757e15f Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 7 Feb 2017 04:44:04 +0100 Subject: [PATCH] The code to add a timer now makes sure to only add the timer if an identical timer is not already present. --- src/timer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/timer.c b/src/timer.c index 45268869e..7020fdf6c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -98,8 +98,22 @@ void timer_reset() int timer_add(void (*callback)(void *priv), int *count, int *enable, void *priv) { + int i = 0; + if (timers_present < TIMERS_MAX) { + if (timers_present != 0) + { + /* This is the sanity check - it goes through all present timers and makes sure we're not adding a timer that already exists. */ + for (i = 0; i < timers_present; i++) + { + if (timers[i].present && (timers[i].callback == callback) && (timers[i].priv == priv) && (timers[i].count == count) && (timers[i].enable == enable)) + { + return; + } + } + } + // pclog("timer_add : adding timer %i\n", timers_present); timers[timers_present].present = 1; timers[timers_present].callback = callback;