Skip to content

Commit c962099

Browse files
authored
Fix SDL_TICKS_PASSED (#234) (#235)
SDL_TICKS_PASSED is meant to compare 32-bit tick counts in a way that works correctly when the counter has recently wrapped around. The Python implementation just did a straight integer comparison.
1 parent 3b3b15b commit c962099

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

sdl2/test/timer_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ def timerfunc(interval, param):
7171
assert len(calls) == orig_calls
7272
# Wait a bit, so the last executing handlers can finish
7373
sdl2.SDL_Delay(10)
74+
75+
def test_SDL_TICKS_PASSED(with_sdl):
76+
for A in (0, 9999, 0xFFFF0000, 0xFFFFFFFF):
77+
assert sdl2.SDL_TICKS_PASSED(A, A)
78+
for delta in (1, 100, 1000000, 0x7FFFFFFF):
79+
assert sdl2.SDL_TICKS_PASSED(A, (A - delta) & 0xFFFFFFFF)
80+
assert not sdl2.SDL_TICKS_PASSED(A, (A + delta) & 0xFFFFFFFF)

sdl2/timer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Macros & inline functions
2424

2525
def SDL_TICKS_PASSED(A, B):
26-
return (B - A) <= 0
26+
return ((A - B) & 0xFFFFFFFF) <= 0x80000000
2727

2828

2929
# Raw ctypes function definitions

0 commit comments

Comments
 (0)