bevy/crates/bevy_time/src
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
..
common_conditions.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
fixed_timestep.rs Add a scope API for world schedules (#8387) 2023-04-16 05:09:33 +00:00
lib.rs Suppress the clippy::type_complexity lint (#8313) 2023-04-06 21:27:36 +00:00
stopwatch.rs Fix various typos (#7096) 2023-01-06 00:43:30 +00:00
time.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
timer.rs Fix timer with zero duration (#8467) 2023-04-24 14:32:42 +00:00