-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Timer tick can lead to a rounding error causing an overflow panic #2361
Labels
C-Bug
An unexpected or incorrect behavior
Comments
It looks like Duration's nanosecond precision can cause // From bevy_core/src/time/timer.rs:220 - 222
self.times_finished = self.percent().floor() as u32;
// Duration does not have a modulo
self.set_elapsed(self.elapsed() - self.duration() * self.times_finished); So |
All the tests appear to pass when doing integer division directly, i.e. if self.finished() {
if self.repeating() {
self.times_finished = (self.elapsed().as_nanos() / self.duration.as_nanos()) as u32;
// Duration does not have a modulo
self.set_elapsed(self.elapsed() - self.duration() * self.times_finished);
} else {
self.times_finished = 1;
self.set_elapsed(self.duration());
}
} |
jacobgardner
added a commit
to jacobgardner/bevy
that referenced
this issue
Jun 19, 2021
ostwilkens
pushed a commit
to ostwilkens/bevy
that referenced
this issue
Jul 27, 2021
# Objective Fixes bevyengine#2361 ## Solution Uses integer division instead of floating-point which prevents precision errors, I think.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bevy version
Confirmed broken on 0.5 and 00d8d5d (HEAD of main at time of bug report)
Operating system & version
Windows 10
What you did
What you expected to happen
No run-time panic. Roughly the same behavior as seen when using
Duration::from_secs_f32
What actually happened
Additional information
For a fixed timestep, I can work around this by using f32 or changing the offset, but if relying on a non-fixed timestep, I imagine this edge-case will periodically appear.
The text was updated successfully, but these errors were encountered: