Weird issue with Time::getMillisecondCounterHiRes()

I have an issue with someone that’s baffling me: if they have not rebooted their system in 2-3 weeks the values that I’m getting from Time::getMillisecondCounterHiRes() end up being all over the place. I often use this method to calculate different things so its messing up the entire application when this happens.

I haven’t been able to reproduce this locally but I’ve seen it happen enough times with this person that I figured it was time to cry for help. Has anyone seen anything similar?

They’re using a fairly-recent Win10 machine.

The issue could be that QueryPerformanceFrequency can jump backwards on some systems. When calculating deltas you should clamp to 0. I’m not really sure there is a fix. It would be nice if Time::getMillisecondCounterHiRes() never returned decreasing values, but that would require a lock or an atomic. Not sure if it’s worth it for a few buggy machines.

Set that single thread to remain on a single processor by using the Windows API SetThreadAffinityMask. Typically, this is the main game thread. While QueryPerformanceCounter and QueryPerformanceFrequency typically adjust for multiple processors, bugs in the BIOS or drivers may result in these routines returning different values as the thread moves from one processor to another. So, it’s best to keep the thread on a single processor.

Interesting! Thanks for the notes.

Time to get to clampin’