Skip to content

Setting window scale factor override to bad value crashes engine #23141

@tbillington

Description

@tbillington

Bevy version and features

0.18

What you did

Attempt to set a scale factor override 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 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 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`!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behaviorP-CrashA sudden unexpected crashS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions