Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow when using sf::Clock for long time #1771

Merged
merged 1 commit into from Apr 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/SFML/System/Win32/ClockImpl.cpp
Expand Up @@ -54,9 +54,9 @@ namespace priv
////////////////////////////////////////////////////////////
Time ClockImpl::getCurrentTime()
{
// Get the frequency of the performance counter
// (it is constant across the program lifetime)
static LARGE_INTEGER frequency = getFrequency();
// Calculate inverse of frequency multiplied by 1000000 to prevent overflow in final calculation
// Frequency is constant across the program lifetime
static double inverse = 1000000.0 / getFrequency().QuadPart;

// Detect if we are on Windows XP or older
static bool oldWindows = isWindowsXpOrOlder();
Expand All @@ -80,7 +80,7 @@ Time ClockImpl::getCurrentTime()
}

// Return the current time as microseconds
return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart);
return sf::microseconds(static_cast<sf::Int64>(time.QuadPart * inverse));
}

} // namespace priv
Expand Down