-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 timer with zero duration #8467
Fix timer with zero duration #8467
Conversation
These fixes look correct: nice work handling this robustly. The other alternative would be to simply make it impossible to construct a timer with zero duration. It's not entirely clear what behavior would be best there though: panicking on construction simply moves the problem. We could enforce this with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately I think this is the least problematic way to fix this panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to make the issue impossible by types, as this means the check will happen several times. Someone doing lots of timers and calling percent
on every frame may notice an impact... but we can revisit that then
This reverts commit e2531b2.
Objective
Timer with zero
Duration
panics attick()
because of division by zero. This PR Fixes #8463 .Solution
checked_div
andchecked_rem
.Changelog
checked_div
. Settimes_finished_this_tick
to u32::MAX when duration is zero.elapsed
toDuration::ZERO
when timer duration is zero.percent
to1.0
when duration is zero.times_finished_this_tick
is not used anywhere, that's why this change will not affect other parts of the project.times_finished_this_tick
is set to0
afterreset()
and before firsttick()
call.