Handmade Hero»Forums»Code
Benjamin Schnur
9 posts
Sleep and timeBeginPeriod
I've been coding along on YouTube and I'm at the end of HH Day 019, but I have an issue related to HH Day 018 (Enforcing a Video Frame Rate).

It appears that my Sleep() doesn't always abide by the granularity set by calling timeBeginPeriod.

The result is that the program breaks when I assert that frame time is less than the target frame time.

The time spent on actual work each frame is computed to be around 8 or 9 ms, and if I comment out the Sleep call, the program doesn't break - of course, we want to lay off the CPU if we can.

As a band-aid fix, I decreased the sleep time by 2 milliseconds (after trying 1), but doing so is obviously super janky / halfway banana cakes.

Has anyone else run into this?
Roderic Bos
70 posts
Sleep and timeBeginPeriod
If you're talking about this assert:
1
Assert(TestSecondsElapsedForFrame < TargetSecondsPerFrame);


Is handled some time later (day 20) and replaced with:

1
2
3
4
if(TestSecondsElapsedForFrame < TargetSecondsPerFrame)
{
   // TODO(casey): LOG MISSED SLEEP HERE
}
Benjamin Schnur
9 posts
Sleep and timeBeginPeriod
Thanks!
44 posts
Sleep and timeBeginPeriod
I miss this too:

TestSecondsElapsedForFrame 0.0334998928 float
TargetSecondsPerFrame 0.0333333351 float


so it's normal?
:cheer: