egui icon indicating copy to clipboard operation
egui copied to clipboard

Egui sometimes panics with `Bug in smart aim code` when using `egui::DragValue` with (small?) `f32` values

Open dolezvo1 opened this issue 1 year ago • 7 comments

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

dolezvo1 avatar Nov 30 '25 10:11 dolezvo1

Yes, getting this all the time. Super annoyng.

hakolao avatar Dec 11 '25 14:12 hakolao

im getting this issue too, its making DragValue completely unusable because every time i try to touch a value the app just crashes

HomelikeBrick42 avatar Dec 12 '25 05:12 HomelikeBrick42

+1 for me. has anyone found any sort of solution for this issue?

tirbofish avatar Dec 17 '25 11:12 tirbofish

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.

dolezvo1 avatar Dec 17 '25 13:12 dolezvo1

Use u32 but not f32 seems solve this problem

Windmill-City avatar Jan 08 '26 07:01 Windmill-City

im getting this when moving a dragvalue with any value less than 1.0

RainGameDev avatar Feb 19 '26 14:02 RainGameDev

@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?

DaforLynx avatar Mar 09 '26 23:03 DaforLynx