From d68d32e12c92df441429bfb576bf0492032c16d3 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Aug 2024 10:35:28 -0700
Subject: [PATCH] Revert "Removing a timer that isn't running is a success."
This reverts commit 795499a529f27469e9c97de596a1606dfc900eec.
This breaks compatibility with SDL2 and there isn't a compelling reason to make this change.
---
src/timer/SDL_timer.c | 8 +++++++-
test/testautomation_timer.c | 4 ++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c
index a936367f9b40a..20050952b949d 100644
--- a/src/timer/SDL_timer.c
+++ b/src/timer/SDL_timer.c
@@ -353,6 +353,7 @@ int SDL_RemoveTimer(SDL_TimerID id)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_TimerMap *prev, *entry;
+ SDL_bool canceled = SDL_FALSE;
if (!id) {
return SDL_InvalidParamError("id");
@@ -376,10 +377,15 @@ int SDL_RemoveTimer(SDL_TimerID id)
if (entry) {
if (!SDL_AtomicGet(&entry->timer->canceled)) {
SDL_AtomicSet(&entry->timer->canceled, 1);
+ canceled = SDL_TRUE;
}
SDL_free(entry);
}
- return 0;
+ if (canceled) {
+ return 0;
+ } else {
+ return SDL_SetError("Timer not found");
+ }
}
#else
diff --git a/test/testautomation_timer.c b/test/testautomation_timer.c
index 98dce1e6797e3..23d971218e374 100644
--- a/test/testautomation_timer.c
+++ b/test/testautomation_timer.c
@@ -142,7 +142,7 @@ static int timer_addRemoveTimer(void *arg)
/* Try to remove timer again (should be a NOOP) */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
- SDLTest_AssertCheck(result == 0, "Check result value, expected: 0, got: %i", result);
+ SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result);
/* Reset state */
param = SDLTest_RandomIntegerInRange(-1024, 1024);
@@ -162,7 +162,7 @@ static int timer_addRemoveTimer(void *arg)
/* Remove timer again and check that callback was called */
result = SDL_RemoveTimer(id);
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
- SDLTest_AssertCheck(result == 0, "Check result value, expected: 0, got: %i", result);
+ SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result);
SDLTest_AssertCheck(g_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", g_timerCallbackCalled);
return TEST_COMPLETED;