FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.64k stars 343 forks source link

Crash when typing into an invisible textbox after deleting its text #362

Closed martin-t closed 1 year ago

martin-t commented 2 years ago

Steps to repro:

1) Create a textbox using this:

use fyrox::gui::{message::*, text_box::*, widget::*};

let text_box = TextBoxBuilder::new(WidgetBuilder::new().with_visibility(false))
    .build(&mut engine.user_interface.build_ctx());

engine
    .user_interface
    .send_message(WidgetMessage::focus(text_box, MessageDirection::ToWidget));

2) Type something into it using your keyboard so the cursor is not at the beginning

3) Clear the text:

engine.user_interface.send_message(TextBoxMessage::text(
    text_box,
    MessageDirection::ToWidget,
    "".to_owned(),
));

4) Try to type into it again, it should crash with something like this:

thread 'main' panicked at 'insertion index (is 3) should be <= len (is 0)', library/alloc/src/vec/mod.rs:1379:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/core/src/panicking.rs:142:14
   2: alloc::vec::Vec<T,A>::insert::assert_failed
             at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/alloc/src/vec/mod.rs:1379:13
   3: fyrox_ui::formatted_text::FormattedText::insert_char
   4: fyrox_ui::text_box::TextBox::insert_char
   5: fyrox_ui::UserInterface::poll_message
   6: rustcycles::client_main::{{closure}}
             at ./src/main.rs:388:39
   7: winit::platform_impl::platform::sticky_exit_callback
   8: winit::platform_impl::platform::x11::EventLoop<T>::run_return::single_iteration
             at /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.2/src/platform_impl/linux/x11/mod.rs:363:17
   9: winit::platform_impl::platform::x11::EventLoop<T>::run_return
             at /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.2/src/platform_impl/linux/x11/mod.rs:488:27
  10: winit::platform_impl::platform::x11::EventLoop<T>::run
             at /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.2/src/platform_impl/linux/x11/mod.rs:503:25
  11: winit::platform_impl::platform::EventLoop<T>::run
             at /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.2/src/platform_impl/linux/mod.rs:755:56
  12: winit::event_loop::EventLoop<T>::run
             at /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.2/src/event_loop.rs:278:9
  13: rustcycles::client_main
             at ./src/main.rs:291:5
  14: rustcycles::run
             at ./src/main.rs:161:13
  15: rustcycles::main
             at ./src/main.rs:143:5
  16: core::ops::function::FnOnce::call_once
             at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
mrDIMAS commented 2 years ago

@martin-t Please confirm that the issue is fixed.

martin-t commented 2 years ago

I updated to the latest commit (102ec67c7ab86cb993864d51c49069dca0ec0fd0) and i still get a crash.

martin-t commented 2 years ago

For completeness, here's the code i am using to repro: https://github.com/rustcycles/rustcycles/commit/c0045376816ae0437a1546fcfc9fcde4002b4a95

(I didn't make a separate test project because of how long fyrox takes to compile but i don't think anything in my game should be affecting this.... I am realizing now I could probably make a quick repro project as an example in the fyrox repo to reuse my build cache...)

martin-t commented 2 years ago

OK, here's a standalone repro case: https://github.com/martin-t/Fyrox/commit/85fbe8d6e78f0765fa39d8031a205ebf5f0b5743

Press some letter keys, click the button, press letter keys again, should crash.