| Summary: | Timer 'slips' occassionally... | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Mark Sibly <blitzmunter> |
| Component: | timer | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED ABANDONED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | don't know | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
Hello, and sorry if you're getting dozens of copies of this message by email. We are closing out bugs that appear to be abandoned in some form. This can happen for lots of reasons: we couldn't reproduce it, conversation faded out, the bug was noted as fixed in a comment but we forgot to mark it resolved, the report is good but the fix is impractical, we fixed it a long time ago without realizing there was an associated report, etc. Individually, any of these bugs might have a better resolution (such as WONTFIX or WORKSFORME or INVALID) but we've added a new resolution of ABANDONED to make this easily searchable and make it clear that it's not necessarily unreasonable to revive a given bug report. So if this bug is still a going concern and you feel it should still be open: please feel free to reopen it! But unless you respond, we'd like to consider these bugs closed, as many of them are several years old and overwhelming our ability to prioritize recent issues. (please note that hundred of bug reports were sorted through here, so we apologize for any human error. Just reopen the bug in that case!) Thanks, --ryan. |
I think there might be a bug in the timer logic. I was trying to write a 60hz timer by having the timer return intervals of 16,17,17,16,17,17 etc to emulate 16.67777ms, but I was seeing slightly longer intervals when measuring the actual elapsed time between timer callbacks. The problem lies in the timer thread loop I think. When SemWaitTimeOut (at the bottom of the loop) returns after a successful timeout, there is a small gap in the code before the next tick=SDL_GetTicks() executes, and if the getticks timer ticks over during that gap, those ticks are 'lost' for good. I fixed this by initializing tick=SDL_GetTicks() before the loop is entered, removing the tick=SDL_GetTicks() from the loop altogether and changing the SemWaitTimeOut to: if( SDL_SemWaitTimeout(data->sem, delay)==SDL_MUTEX_TIMEDOUT ){ tick=now+delay; }else{ tick=SDL_GetTicks(); } In other words, after a successfull timeout, tick ignores SDL_GetTicks() altogether and simply advances to what it *should* be. Not sure if this is the right way to fix it, or what it means when a new timer is added (will probably be out but not by much?), but with this fix in place I now get a very solid 60hz timer. Another little tweak I made was to replace this: delay = (current->scheduled - tick); ...with this... delay = (current->scheduled - tick - 1); This effectively makes the timer code 'spin' for the last ms before a timer fires, which makes for a much smoother result, ie: I get measured intervals of 16,17,17,16,17,17 90% of the time. Without this in place, I get frequent drops to an interval of 18 - which is compensated for later by a 15 or a few extra 16s! Probably not worth adding though...