linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.53k stars 569 forks source link

Crash in example switches #1458

Closed djeedai closed 3 years ago

djeedai commented 3 years ago

druid 65eb306018cf0990cce4305952924c2303ed6af9

cargo run --example switches

Focus the text after the "1" and press ".5". On pressing "5" the program crashes.

thread 'main' panicked at 'assertion failed: self.is_char_boundary(n)', C:\Users\<user>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\string.rs:1555:29
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:85
   2: core::panicking::panic
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:50
   3: alloc::string::String::replace_range<core::ops::range::Range<usize>>
             at C:\Users\<user>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\string.rs:1555
   4: druid::text::editable_text::{{impl}}::edit<str*>
             at .\src\text\editable_text.rs:90
   5: druid::text::editor::Editor<alloc::string::String>::insert<alloc::string::String>
             at .\src\text\editor.rs:239
   6: druid::text::editor::Editor<alloc::string::String>::do_edit<alloc::string::String>
             at .\src\text\editor.rs:183
   7: druid::widget::textbox::{{impl}}::event<alloc::string::String>
             at .\src\widget\textbox.rs:372
   8: druid::widget::parse::{{impl}}::event<f64,druid::widget::textbox::TextBox<alloc::string::String>>
             at .\src\widget\parse.rs:40
   9: druid::widget::lens_wrap::{{impl}}::event::{{closure}}<switches::DemoState,core::option::Option<f64>,druid::lens::lens::Then<switches::demo_state_derived_lenses::stepper_value, druid::lens::lens::Map<closure-0, closure-1>, f64>,druid::widget::parse::Parse
             at .\src\widget\lens_wrap.rs:81
  10: druid::lens::lens::{{impl}}::with_mut<f64,core::option::Option<f64>,closure-0,closure-1,tuple<>,closure-0>
             at .\src\lens\lens.rs:383
  11: druid::lens::lens::{{impl}}::with_mut::{{closure}}<switches::demo_state_derived_lenses::stepper_value,druid::lens::lens::Map<closure-0, closure-1>,switches::DemoState,f64,core::option::Option<f64>,tuple<>,closure-0>
             at .\src\lens\lens.rs:338
  12: switches::{{impl}}::with_mut<tuple<>,closure-0>
             at .\examples\switches.rs:21
  13: druid::lens::lens::{{impl}}::with_mut<switches::demo_state_derived_lenses::stepper_value,druid::lens::lens::Map<closure-0, closure-1>,switches::DemoState,f64,core::option::Option<f64>,tuple<>,closure-0>
             at .\src\lens\lens.rs:338
  14: druid::widget::lens_wrap::{{impl}}::event<switches::DemoState,core::option::Option<f64>,druid::lens::lens::Then<switches::demo_state_derived_lenses::stepper_value, druid::lens::lens::Map<closure-0, closure-1>, f64>,druid::widget::parse::Parse<druid::widge
             at .\src\widget\lens_wrap.rs:80
  15: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  16: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  17: druid::widget::padding::{{impl}}::event<switches::DemoState>
             at .\src\widget\padding.rs:74
  18: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  19: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  20: druid::widget::flex::{{impl}}::event<switches::DemoState>
             at .\src\widget\flex.rs:601
  21: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  22: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  23: druid::widget::padding::{{impl}}::event<switches::DemoState>
             at .\src\widget\padding.rs:74
  24: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  25: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  26: druid::widget::flex::{{impl}}::event<switches::DemoState>
             at .\src\widget\flex.rs:601
  27: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  28: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  29: druid::widget::align::{{impl}}::event<switches::DemoState>
             at .\src\widget\align.rs:81
  30: druid::widget::widget::{{impl}}::event<switches::DemoState>
             at .\src\widget\widget.rs:239
  31: druid::core::WidgetPod<switches::DemoState, alloc::boxed::Box<Widget<switches::DemoState>>>::event<switches::DemoState,alloc::boxed::Box<Widget<switches::DemoState>>>
             at .\src\core.rs:787
  32: druid::window::Window<switches::DemoState>::event<switches::DemoState>
             at .\src\window.rs:222
  33: druid::win_handler::Inner<switches::DemoState>::do_window_event<switches::DemoState>
             at .\src\win_handler.rs:394
  34: druid::win_handler::AppState<switches::DemoState>::do_window_event<switches::DemoState>
             at .\src\win_handler.rs:503
  35: druid::win_handler::{{impl}}::key_down<switches::DemoState>
             at .\src\win_handler.rs:812
  36: druid_shell::platform::windows::window::{{impl}}::window_proc::{{closure}}
             at f:\dev\druid\druid-shell\src\platform\windows\window.rs:899
  37: druid_shell::platform::windows::window::MyWndProc::with_wnd_state<closure-10,bool>
             at f:\dev\druid\druid-shell\src\platform\windows\window.rs:425
  38: druid_shell::platform::windows::window::{{impl}}::window_proc
             at f:\dev\druid\druid-shell\src\platform\windows\window.rs:888
  39: druid_shell::platform::windows::window::win_proc_dispatch
             at f:\dev\druid\druid-shell\src\platform\windows\window.rs:1462
  40: CallWindowProcW
  41: DispatchMessageW
  42: druid_shell::platform::windows::application::Application::run
             at f:\dev\druid\druid-shell\src\platform\windows\application.rs:145
  43: druid_shell::application::Application::run
             at f:\dev\druid\druid-shell\src\application.rs:153
  44: druid::app::AppLauncher<switches::DemoState>::launch<switches::DemoState>
             at .\src\app.rs:183
  45: switches::main
             at .\examples\switches.rs:72
  46: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\<user>\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
cmyr commented 3 years ago

thanks, i'll take a look at this :)

cmyr commented 3 years ago

Okay, this is a known issue with the parse widget, see #1425. This is approximately addressed in #1377, which I should finish up and get merged.