bevy/crates/bevy_time
Rostyslav Toch e2531b2273
Fix timer with zero duration (#8467)
# Objective

Timer with zero `Duration` panics at `tick()` because of division by
zero. This PR Fixes #8463 .

## Solution

- Handle division by zero separately with `checked_div` and
`checked_rem`.

---

## Changelog


- Replace division with `checked_div`. Set `times_finished_this_tick` to
u32::MAX when duration is zero.
- Set `elapsed` to `Duration::ZERO` when timer duration is zero.
- Set `percent` to `1.0` when duration is zero.
- `times_finished_this_tick` is [not used
anywhere](https://github.com/bevyengine/bevy/search?q=times_finished_this_tick),
that's why this change will not affect other parts of the project.
- `times_finished_this_tick` is set to `0` after `reset()` and before
first `tick()` call.
2023-04-24 14:32:42 +00:00
..
src Fix timer with zero duration (#8467) 2023-04-24 14:32:42 +00:00
Cargo.toml chore: Release (#7920) 2023-03-06 05:13:36 +00:00