I have a strange bug where every clock object goes negative, on certain systems, but not all the time.
I think the problem could be with QueryPerformanceCounter in ClockImpl.cpp. This function can fail on some systems, and because the variable used to store the time is declared locally to the function, it could be any number.
Latest version of SFML has this in ClockImpl.cpp:
HANDLE currentThread = GetCurrentThread();
DWORD_PTR previousMask = SetThreadAffinityMask(currentThread, 1);
// Get the frequency of the performance counter
// (it is constant across the program lifetime)
static LARGE_INTEGER frequency = getFrequency();
// Get the current time
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
// Restore the thread affinity
SetThreadAffinityMask(currentThread, previousMask);
// Return the current time as microseconds
return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart);
Previous versions had this (in Platform.cpp - before it got moved around):
static LARGE_INTEGER frequency;
static BOOL useHighPerformanceTimer = QueryPerformanceFrequency(&frequency);
if (useHighPerformanceTimer)
{
// High performance counter available : use it
LARGE_INTEGER currentTime;
QueryPerformanceCounter(¤tTime);
return currentTime.QuadPart * 1000 / frequency.QuadPart;
}
else
{
// High performance counter not available: use GetTickCount (less accurate)
return GetTickCount();
}
So at least if the QueryPerformanceFrequency failed, GetTickCount would be a backup in this case, and not return an unknown value as the current implementation will do.
Is this a bug, or have I misunderstood?
Regards
Ed