Egui sometimes panics with `Bug in smart aim code` when using `egui::DragValue` with (small?) `f32` values
Describe the bug
I'm using egui 0.32.2 and I just had it crash with "Bug in smart aim code" when using an egui::DragValue. I can see that there was a commit concerning that file 27 days ago which most likely introduced this, because the string wasn't present in the file before it.
To Reproduce
I'm using egui::DragValue with 0.01 speed and range x..=(1.0-x) where x is a dynamically calculated floating point number between 0 and 0.5.
let x = 25.0 / w;
egui::DragValue::new(&mut value).range(x..=(1.0-x)).speed(0.01)
I can reproduce the behaviour fairly reliably when setting w to 137, which happens to be a prime number.
w: 137, x: 0.18248175, initial value: 0.81751823
thread 'main' (3248) panicked at C:\Users\dolezvo1\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\emath-0.33.2\src\smart_aim.rs:90:13:
Bug in smart aim code
stack backtrace:
0: std::panicking::panic_handler
at /rustc/6380899f32599ea25615d4ccd708d0e8da652b0c/library\std\src\panicking.rs:698
1: core::panicking::panic_fmt
at /rustc/6380899f32599ea25615d4ccd708d0e8da652b0c/library\core\src\panicking.rs:80
2: emath::smart_aim::best_in_range_f64
at C:\Users\dolezvo1\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\emath-0.33.2\src\smart_aim.rs:90
3: egui::widgets::drag_value::impl$1::ui
at C:\Users\dolezvo1\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\egui-0.33.2\src\widgets\drag_value.rs:649
...
Expected behavior Not panicking, I suppose
Desktop:
- OS: Windows 10
Yes, getting this all the time. Super annoyng.
im getting this issue too, its making DragValue completely unusable because every time i try to touch a value the app just crashes
+1 for me. has anyone found any sort of solution for this issue?
At least for me, multiplying the values by 100 before passing it to the DragValue and then dividing the result by 100 afterwards seems to work as a mitigation.
Use u32 but not f32 seems solve this problem
im getting this when moving a dragvalue with any value less than 1.0
@Fyrecean I've gotten this bug on u32 values as well (egui 0.33) sometimes, and only with the debug profile. The place it crashes at seems to depend on the range of the DragValue. Does the fix address that as well?