Setting window scale factor override to bad value crashes engine
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
0.18
## What you did
Attempt to set a [scale factor override](https://docs.rs/bevy_window/0.18.0/src/bevy_window/window.rs.html#892) value through bevy inspector egui by changing the None value to Some(x).
## What went wrong
When changing the None to Some, the scale factor value uses the f32 default of 0. This triggers an [assert](https://github.com/rust-windowing/winit/blob/587ade844dfb0eada3696ba1cb263c66eea80581/dpi/src/lib.rs#L563) inside `dpi`, skipping the usual bevy error handling machinery and panicing the process.
While it's unlikely that the user intentionally wants a zero scale factor, editor tools like inspector egui or the upcoming entity inspector make scenarios like this much more common. The engine also shouldn't crash due to such a minor misconfiguration.
## Possible solutions
- Upstream a change to `dpi` that won't panic, eg by using Option/Result.
- Use the same [validation function](https://github.com/rust-windowing/winit/blob/587ade844dfb0eada3696ba1cb263c66eea80581/dpi/src/lib.rs#L143) `dpi` uses to ensure we only pass "good" scale factor values to the function. Possibly defaulting to 1.0 and logging an error?
- Somehow tie this error into using Bevys error handling machinery so it's not a straight panic.
- ?
## Additional information
```
thread 'main' (1375470) panicked at /home/choc/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dpi-0.1.2/src/lib.rs:563:9:
assertion failed: validate_scale_factor(scale_factor)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_winit::system::changed_windows`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
```
Contributor guide
Assessment
This issue has not been assessed yet.