Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
c4dd866a
Unverified
Commit
c4dd866a
authored
Jun 11, 2020
by
Rémi Verschelde
Committed by
GitHub
Jun 11, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #38958 from lawnjelly/time_overflow_4
Fix overflow condition with QueryPerformanceCounter
parents
7217a7ed
db9fa881
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
os_uwp.cpp
platform/uwp/os_uwp.cpp
+19
-2
os_windows.cpp
platform/windows/os_windows.cpp
+19
-2
No files found.
platform/uwp/os_uwp.cpp
View file @
c4dd866a
...
...
@@ -535,11 +535,28 @@ void OS_UWP::delay_usec(uint32_t p_usec) const {
uint64_t
OS_UWP
::
get_ticks_usec
()
const
{
uint64_t
ticks
;
uint64_t
time
;
// This is the number of clock ticks since start
QueryPerformanceCounter
((
LARGE_INTEGER
*
)
&
ticks
);
// Divide by frequency to get the time in seconds
time
=
ticks
*
1000000L
/
ticks_per_second
;
// original calculation shown below is subject to overflow
// with high ticks_per_second and a number of days since the last reboot.
// time = ticks * 1000000L / ticks_per_second;
// we can prevent this by either using 128 bit math
// or separating into a calculation for seconds, and the fraction
uint64_t
seconds
=
ticks
/
ticks_per_second
;
// compiler will optimize these two into one divide
uint64_t
leftover
=
ticks
%
ticks_per_second
;
// remainder
uint64_t
time
=
(
leftover
*
1000000L
)
/
ticks_per_second
;
// seconds
time
+=
seconds
*
1000000L
;
// Subtract the time at game start to get
// the time since the game started
time
-=
ticks_start
;
...
...
platform/windows/os_windows.cpp
View file @
c4dd866a
...
...
@@ -403,12 +403,29 @@ void OS_Windows::delay_usec(uint32_t p_usec) const {
uint64_t
OS_Windows
::
get_ticks_usec
()
const
{
uint64_t
ticks
;
uint64_t
time
;
// This is the number of clock ticks since start
if
(
!
QueryPerformanceCounter
((
LARGE_INTEGER
*
)
&
ticks
))
ticks
=
(
UINT64
)
timeGetTime
();
// Divide by frequency to get the time in seconds
time
=
ticks
*
1000000L
/
ticks_per_second
;
// original calculation shown below is subject to overflow
// with high ticks_per_second and a number of days since the last reboot.
// time = ticks * 1000000L / ticks_per_second;
// we can prevent this by either using 128 bit math
// or separating into a calculation for seconds, and the fraction
uint64_t
seconds
=
ticks
/
ticks_per_second
;
// compiler will optimize these two into one divide
uint64_t
leftover
=
ticks
%
ticks_per_second
;
// remainder
uint64_t
time
=
(
leftover
*
1000000L
)
/
ticks_per_second
;
// seconds
time
+=
seconds
*
1000000L
;
// Subtract the time at game start to get
// the time since the game started
time
-=
ticks_start
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment