geom3trik / tuix

Cross-platform GUI toolkit written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on cursor/arrow up key

WeirdConstructor opened this issue · comments

In HexoSynth, if I hit arrow key up, without doing anything else before, I get the following crash backtrace:

thread 'main' panicked at 'index out of bounds: the len is 68 but the index is 16777215', /home/weicon/devel/rust/tuix/core/
src/tree/tree.rs:133:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ff2c947c00f867b9f012e28ba88cecfbe556f904/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/ff2c947c00f867b9f012e28ba88cecfbe556f904/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/ff2c947c00f867b9f012e28ba88cecfbe556f904/library/core/src/panicking.rs:69:5
   3: tuix_core::tree::tree::Tree::get_prev_sibling
   4: <tuix_widgets::containers::listbox::List as tuix_core::widget::widget::Widget>::on_event
   5: <tuix_widgets::tab::TabBar2 as tuix_core::widget::widget::Widget>::on_event
   6: tuix_core::events::event_manager::EventManager::flush_events
   7: tuix_glutin::application::Application::run::{{closure}}
   8: winit::platform_impl::platform::x11::EventLoop<T>::run
   9: winit::platform_impl::platform::EventLoop<T>::run
  10: winit::event_loop::EventLoop<T>::run
  11: tuix_glutin::application::Application::run
  12: tuix_gui::jack::start_backend
  13: tuix_gui::synth::start

The "listbox" I am using is probably the Tabs.

What probably happens is, that the Entity::null() that is used to initialize the "checked_entity" in Listbox is passed into get_prev_sibling and that does call Entity::index() on a null entity, which returns 16777215. Not sure however where/how to fix. My defensive programming guts tell me that either Entity::index() always returns a valid value. Or it should return Option<usize>. Or all callers should check if they are holding a null entity (which boils down to a similar if as the Option<usize> would), or they should consistently check if the index is out of range, like set_first_child does (it returns a TreeError::InvalidSibling in that case).

On the other hand, the List should probably check for itself?