Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertion failed: !timer.being_activated #6187

Closed
Enyium opened this issue Sep 18, 2024 · 19 comments · Fixed by #6549
Closed

assertion failed: !timer.being_activated #6187

Enyium opened this issue Sep 18, 2024 · 19 comments · Fixed by #6549
Labels
a:tool classes & property system runtime core classes (SharedVector,SharedString) and property system (mO,bS) bug Something isn't working

Comments

@Enyium
Copy link
Contributor

Enyium commented Sep 18, 2024

I use Rust on Windows 10 with Slint v1.7.2.

For the first time, I encountered the following panic, which didn't happen in many cases that should be identical from my point of view:

thread 'main' panicked at C:\Users\...\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.7.2\timers.rs:260:21:
assertion failed: !timer.being_activated

I don't have much information about it. But I think it could have happened in the context of dropping the Timer that I hold in my App struct by setting the respective struct field to None. In my app, I often drop Timers like this without stopping them first.

@tronical
Copy link
Member

Is it possible perhaps that the timer was dropped in its own timeout callback?

(In any case, this is a bug, but we need to find a way to reproduce it :-/

@tronical tronical added bug Something isn't working a:tool classes & property system runtime core classes (SharedVector,SharedString) and property system (mO,bS) labels Sep 18, 2024
@tronical
Copy link
Member

(cc @ogoffart - would this area be... acceptable?)

@Enyium
Copy link
Contributor Author

Enyium commented Sep 18, 2024

Is it possible perhaps that the timer was dropped in its own timeout callback?

I use the Timer instance that this panic should've been associated with in the following way:

  • Let App::on_timer(&mut self, self_weak: rc::Weak<RefCell<App>>) be the timer callback.
  • When the sequence of timer callback calls should start, on_timer() is called manually.
  • Depending on whether the sequence should be continued, the code in on_timer() creates a new Timer, starts it with timer.start(TimerMode::SingleShot, ...) and saves it in the App instance. When the sequence shouldn't be continued, None is saved instead.
  • The timer closure calls on_timer().

I've just repeated the process many times, but couldn't reproduce the panic. It may be a heisenbug.

@ogoffart ogoffart added the needs info Further information from the reporter is requested label Sep 18, 2024
@ogoffart
Copy link
Member

I thought it happens if, for example, one call slint::platform::update_timers_and_animations() from a timer callback, but i tried to reproduce with this code:

    let t1 = Timer::default();
    t1.start(TimerMode::Repeated, Duration::from_millis(1), move || {
        slint::platform::update_timers_and_animations();
    });

and we get another panic ("Recursion in timer code" line 257) so that's not the same.

I would love to see a reproducable test case. or even just a backtrace.

@Enyium
Copy link
Contributor Author

Enyium commented Oct 1, 2024

I would love to see [...] even just a backtrace.

After always running my app with $env:RUST_BACKTRACE=1; cargo run since posting this issue, I got the following also timer-related panic, that doesn't show the same error message, though.
thread 'main' panicked at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:267:51:
invalid key
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\std\src\panicking.rs:652
   1: core::panicking::panic_fmt
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\panicking.rs:72
   2: core::panicking::panic
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library\core\src\panicking.rs:146
   3: slab::impl$5::index_mut<i_slint_core::timers::TimerData>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slab-0.4.9\src\lib.rs:1220
   4: i_slint_core::timers::impl$2::maybe_activate_timers::closure$1
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:267      
   5: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::try_with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\thread\local.rs:283
   6: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\thread\local.rs:260
   7: i_slint_core::timers::TimerList::maybe_activate_timers             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:256      
   8: i_slint_core::platform::update_timers_and_animations  
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\platform.rs:236    
   9: i_slint_backend_winit::event_loop::impl$6::new_events
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:563
  10: winit::application::impl$0::new_events<i_slint_backend_winit::event_loop::EventLoopState,i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\application.rs:230   
  11: i_slint_backend_winit::event_loop::impl$7::new_events::closure$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:611
  12: i_slint_backend_winit::event_loop::CURRENT_WINDOW_TARGET::set<i_slint_backend_winit::event_loop::impl$7::new_events::closure_env$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >,tuple$<> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\scoped-tls-hkt-0.1.4\src\lib.rs:265   
  13: i_slint_backend_winit::event_loop::impl$7::new_events<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:611
  14: winit::event_loop::dispatch_event_for_app
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\event_loop.rs:641    
  15: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:76
  16: winit::platform_impl::windows::event_loop::impl$3::run_on_demand::closure$0<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:253
  17: alloc::boxed::impl$49::call_mut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPlaceholder> > >,dyn$<core::ops::function::FnMut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPla
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\alloc\src\boxed.rs:2070
  18: winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:236
  19: core::panic::unwind_safe::impl$25::call_once<tuple$<>,winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\core\src\panic\unwind_safe.rs:272
  20: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\panicking.rs:559
  21: winit::platform_impl::windows::keyboard_layout::impl$11::default
  22: std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> > > 
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\panicking.rs:523
  23: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\panic.rs:149
  24: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::catch_unwind<winit::platform_impl::windows::event_loop::UserEventPlaceholder,tuple$<>,winit::platform_impl::windows::event_
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:173
  25: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_event_handler<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:230
  26: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_new_events<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:351
  27: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::move_state_to<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:308
  28: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::wakeup<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:205
  29: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::wait_and_dispatch_message<i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:419
  30: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::Ev
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:259
  31: winit::platform::run_on_demand::impl$0::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slin
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:89
  32: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend_winit::eve
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:75
  33: i_slint_backend_winit::event_loop::EventLoopState::run             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:684
  34: i_slint_backend_winit::impl$2::run_event_loop
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\lib.rs:383  35: 
slint::run_event_loop::closure$0
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-1.8.0\lib.rs:239
  36: i_slint_backend_selector::with_platform::closure$0<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:137   
  37: i_slint_core::context::with_global_context::closure$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::a
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\context.rs:78
  38: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::try_with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\thread\local.rs:283
  39: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result<tup
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\std\src\thread\local.rs:260
  40: i_slint_core::context::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::Platfor
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\context.rs:77
  41: i_slint_backend_selector::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_platform::closure_env$0<tuple$<>,slint::run_event_loop::closure_env$0> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:144   
  42: i_slint_backend_selector::with_platform<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:137   
  43: slint::run_event_loop
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-1.8.0\lib.rs:239
  44: redacted::main
             at .\src\main.rs:21
  45: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` 
for a verbose backtrace.

.\src\main.rs:21 is:

    slint::run_event_loop()?;

@ogoffart ogoffart added need triaging Issue that the owner of the area still need to triage and removed needs info Further information from the reporter is requested labels Oct 1, 2024
@Enyium
Copy link
Contributor Author

Enyium commented Oct 7, 2024

invalid key happened again; key difference to previous backtrace in point 21.
thread 'main' panicked at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:267:51:
invalid key
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74
   2: core::panicking::panic
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:148
   3: slab::impl$5::index_mut<i_slint_core::timers::TimerData>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slab-0.4.9\src\lib.rs:1220
   4: i_slint_core::timers::impl$2::maybe_activate_timers::closure$1
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:267      
   5: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::try_with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
   6: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
   7: i_slint_core::timers::TimerList::maybe_activate_timers             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\timers.rs:256      
   8: i_slint_core::platform::update_timers_and_animations  
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\platform.rs:236    
   9: i_slint_backend_winit::event_loop::impl$6::new_events
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:563
  10: winit::application::impl$0::new_events<i_slint_backend_winit::event_loop::EventLoopState,i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\application.rs:230   
  11: i_slint_backend_winit::event_loop::impl$7::new_events::closure$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:611
  12: i_slint_backend_winit::event_loop::CURRENT_WINDOW_TARGET::set<i_slint_backend_winit::event_loop::impl$7::new_events::closure_env$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >,tuple$<> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\scoped-tls-hkt-0.1.4\src\lib.rs:265   
  13: i_slint_backend_winit::event_loop::impl$7::new_events<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:611
  14: winit::event_loop::dispatch_event_for_app
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\event_loop.rs:641    
  15: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:76
  16: winit::platform_impl::windows::event_loop::impl$3::run_on_demand::closure$0<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:253
  17: alloc::boxed::impl$49::call_mut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPlaceholder> > >,dyn$<core::ops::function::FnMut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPla
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\alloc\src\boxed.rs:2077
  18: winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:236
  19: core::panic::unwind_safe::impl$25::call_once<tuple$<>,winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\panic\unwind_safe.rs:272
  20: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:557
  21: winit::platform_impl::windows::window::TASKBAR_LIST2::constant$0::closure$1
  22: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:521
  23: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panic.rs:350
  24: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::catch_unwind<winit::platform_impl::windows::event_loop::UserEventPlaceholder,tuple$<>,winit::platform_impl::windows::event_
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:173
  25: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_event_handler<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:230
  26: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_new_events<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:351
  27: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::move_state_to<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:308
  28: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::wakeup<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:205
  29: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::wait_and_dispatch_message<i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:419
  30: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::Ev
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:259
  31: winit::platform::run_on_demand::impl$0::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slin
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:89
  32: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend_winit::eve
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:75
  33: i_slint_backend_winit::event_loop::EventLoopState::run             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\event_loop.rs:684
  34: i_slint_backend_winit::impl$2::run_event_loop
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-winit-1.8.0\lib.rs:383  35: slint::run_event_loop::closure$0
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-1.8.0\lib.rs:239
  36: i_slint_backend_selector::with_platform::closure$0<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:137
  37: i_slint_core::context::with_global_context::closure$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::a
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\context.rs:78      
  38: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::try_with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
  39: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result<tup
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
  40: i_slint_core::context::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::Platfor
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-core-1.8.0\context.rs:77      
  41: i_slint_backend_selector::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_platform::closure_env$0<tuple$<>,slint::run_event_loop::closure_env$0> >   
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:144
  42: i_slint_backend_selector::with_platform<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-backend-selector-1.8.0\lib.rs:137
  43: slint::run_event_loop
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-1.8.0\lib.rs:239
  44: redacted::main
             at .\src\main.rs:22
  45: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >     
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@tronical
Copy link
Member

tronical commented Oct 7, 2024

I don't understand how this is possible :(

This is the offending mutable indexing call:

            let timers_to_process = core::mem::take(&mut timers.borrow_mut().active_timers);
            {
                let mut timers = timers.borrow_mut();
                for active_timer in &timers_to_process {
                    let timer = &mut timers.timers[active_timer.id];
                    assert!(!timer.being_activated);
                    timer.being_activated = true;
                }
            }

The only situation that I can imagine this panicking is if the same timer id exists twice in active_timers (now timers_to_process) and an earlier removal removed only once entry and the other one is still there, so by the time this function (maybe_activate_timers()) runs, the invalid timer lingers around. But I don't understand how that could happen yet :(

@Enyium
Copy link
Contributor Author

Enyium commented Oct 7, 2024

Is this quote from slab relevant?

It is important to note that keys may be reused. In other words, once a value associated with a given key is removed from a slab, that key may be returned from future calls to insert.

Could you maybe add debug-build-only code at different places that temporarily does many more checks of all kinds? (Or, if you think this is better, even behind a secret feature called debug-issue-6187.)

@tronical
Copy link
Member

Is this quote from slab relevant?

It is important to note that keys may be reused. In other words, once a value associated with a given key is removed from a slab, that key may be returned from future calls to insert.

Yeah, I was also contemplating switching to generational area like we use it elsewhere. But this particular situation, use after removal is supposed to be already handled with the removed boolean.

Could you maybe add debug-build-only code at different places that temporarily does many more checks of all kinds? (Or, if you think this is better, even behind a secret feature called debug-issue-6187.)

That could be done. How easily can you trigger the bug in your application?

@tronical
Copy link
Member

Could you try this in your Cargo.toml and use a debug build? I added a bunch of assertions that might help us catch the bug.

[patch.crates-io]
slint = { git = "https://github.com/slint-ui/slint", branch = "simon/timer-debug" }
slint-build = { git = "https://github.com/slint-ui/slint", , branch = "simon/timer-debug" }

@Enyium
Copy link
Contributor Author

Enyium commented Oct 10, 2024

You have a double-comma in the TOML table (, , ) - also in the other issue.

How easily can you trigger the bug in your application?

I'm usually productively running the app's debug build one to two times a day, and I told you of every panic in this context. I never got one of these panics through short unproductive app usage, even though I tried with repeated actions.

@Enyium
Copy link
Contributor Author

Enyium commented Oct 10, 2024

Despite your additions, the same index_mut() panicked with invalid key.
thread 'main' panicked at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\timers.rs:279:51:    
invalid key
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74
   2: core::panicking::panic
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:148
   3: slab::impl$5::index_mut<i_slint_core::timers::TimerData> 
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slab-0.4.9\src\lib.rs:1220
   4: i_slint_core::timers::impl$2::maybe_activate_timers::closure$1
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\timers.rs:279
   5: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::try_with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
   6: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
   7: i_slint_core::timers::TimerList::maybe_activate_timers
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\timers.rs:256
   8: i_slint_core::platform::update_timers_and_animations     
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\platform.rs:236
   9: i_slint_backend_winit::event_loop::impl$6::new_events    
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\winit\event_loop.rs:563    
  10: winit::application::impl$0::new_events<i_slint_backend_winit::event_loop::EventLoopState,i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\application.rs:230
  11: i_slint_backend_winit::event_loop::impl$7::new_events::closure$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\winit\event_loop.rs:611    
  12: i_slint_backend_winit::event_loop::CURRENT_WINDOW_TARGET::set<i_slint_backend_winit::event_loop::impl$7::new_events::closure_env$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >,tuple$<> >     
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\scoped-tls-hkt-0.1.5\src\lib.rs:258
  13: i_slint_backend_winit::event_loop::impl$7::new_events<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\winit\event_loop.rs:611    
  14: winit::event_loop::dispatch_event_for_app
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\event_loop.rs:641
  15: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:76
  16: winit::platform_impl::windows::event_loop::impl$3::run_on_demand::closure$0<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:253
  17: alloc::boxed::impl$49::call_mut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPlaceholder> > >,dyn$<core::ops::function::FnMut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPla
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\alloc\src\boxed.rs:2077
  18: winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:236
  19: core::panic::unwind_safe::impl$25::call_once<tuple$<>,winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\panic\unwind_safe.rs:272
  20: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >    
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:557
  21: winit::platform_impl::windows::window::TASKBAR_LIST2::constant$0::closure$1
  22: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:521
  23: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >        
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panic.rs:350
  24: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::catch_unwind<winit::platform_impl::windows::event_loop::UserEventPlaceholder,tuple$<>,winit::platform_impl::windows::event_
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:173
  25: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_event_handler<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:230
  26: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_new_events<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:351
  27: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::move_state_to<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:308
  28: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::wakeup<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:205
  29: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::wait_and_dispatch_message<i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:419
  30: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::Ev
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:259
  31: winit::platform::run_on_demand::impl$0::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slin
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:89
  32: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend_winit::eve
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:75
  33: i_slint_backend_winit::event_loop::EventLoopState::run
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\winit\event_loop.rs:684    
  34: i_slint_backend_winit::impl$2::run_event_loop
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\winit\lib.rs:383
  35: slint::run_event_loop::closure$0
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\api\rs\slint\lib.rs:239
  36: i_slint_backend_selector::with_platform::closure$0<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\selector\lib.rs:137        
  37: i_slint_core::context::with_global_context::closure$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::a
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\context.rs:78
  38: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::try_with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
  39: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result<tup
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
  40: i_slint_core::context::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::Platfor
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\core\context.rs:77
  41: i_slint_backend_selector::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_platform::closure_env$0<tuple$<>,slint::run_event_loop::closure_env$0> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\selector\lib.rs:144        
  42: i_slint_backend_selector::with_platform<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\internal\backends\selector\lib.rs:137        
  43: slint::run_event_loop
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\59ee7ed\api\rs\slint\lib.rs:239
  44: redacted::main
             at .\src\main.rs:22
  45: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` 
for a verbose backtrace.

@tronical
Copy link
Member

Thanks for testing. I've found three bugs in the code, two fixed in 2f9cea5 and one in 787e13b . I was able to reproduce one of the invalid key panics, but oddly not the one you ran into. Perhaps however that was the consequence of incorrect id re-use, that 787e13b would fix. I'd be very grateful if you could test the current simon/timer-debug branch once more. Thanks again :)

@Enyium
Copy link
Contributor Author

Enyium commented Oct 11, 2024

The same index_mut() still panics with invalid key.
thread 'main' panicked at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\timers.rs:279:51:    
invalid key
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74
   2: core::panicking::panic
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:148
   3: slab::impl$5::index_mut<i_slint_core::timers::TimerData> 
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slab-0.4.9\src\lib.rs:1220
   4: i_slint_core::timers::impl$2::maybe_activate_timers::closure$1
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\timers.rs:279
   5: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::try_with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
   6: std::thread::local::LocalKey<core::cell::RefCell<i_slint_core::timers::TimerList> >::with<core::cell::RefCell<i_slint_core::timers::TimerList>,i_slint_core::timers::impl$2::maybe_activate_timers::closure_env$1,bool>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
   7: i_slint_core::timers::TimerList::maybe_activate_timers   
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\timers.rs:256
   8: i_slint_core::platform::update_timers_and_animations     
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\platform.rs:236
   9: i_slint_backend_winit::event_loop::impl$6::new_events    
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\winit\event_loop.rs:563    
  10: winit::application::impl$0::new_events<i_slint_backend_winit::event_loop::EventLoopState,i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\application.rs:230
  11: i_slint_backend_winit::event_loop::impl$7::new_events::closure$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\winit\event_loop.rs:611    
  12: i_slint_backend_winit::event_loop::CURRENT_WINDOW_TARGET::set<i_slint_backend_winit::event_loop::impl$7::new_events::closure_env$0<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >,tuple$<> >     
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\scoped-tls-hkt-0.1.5\src\lib.rs:258
  13: i_slint_backend_winit::event_loop::impl$7::new_events<i_slint_backend_winit::SlintUserEvent,ref_mut$<i_slint_backend_winit::event_loop::EventLoopState> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\winit\event_loop.rs:611    
  14: winit::event_loop::dispatch_event_for_app
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\event_loop.rs:641
  15: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:76
  16: winit::platform_impl::windows::event_loop::impl$3::run_on_demand::closure$0<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:253
  17: alloc::boxed::impl$49::call_mut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPlaceholder> > >,dyn$<core::ops::function::FnMut<tuple$<enum2$<winit::event::Event<winit::platform_impl::windows::event_loop::UserEventPla
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\alloc\src\boxed.rs:2077
  18: winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:236
  19: core::panic::unwind_safe::impl$25::call_once<tuple$<>,winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\panic\unwind_safe.rs:272
  20: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >    
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:557
  21: winit::platform_impl::windows::window::TASKBAR_LIST2::constant$0::closure$1
  22: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panicking.rs:521
  23: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::windows::event_loop::runner::impl$3::call_event_handler::closure_env$0<winit::platform_impl::windows::event_loop::UserEventPlaceholder> >,tuple$<> >        
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\panic.rs:350
  24: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::catch_unwind<winit::platform_impl::windows::event_loop::UserEventPlaceholder,tuple$<>,winit::platform_impl::windows::event_
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:173
  25: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_event_handler<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:230
  26: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::call_new_events<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:351
  27: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::move_state_to<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:308
  28: winit::platform_impl::windows::event_loop::runner::EventLoopRunner<winit::platform_impl::windows::event_loop::UserEventPlaceholder>::wakeup<winit::platform_impl::windows::event_loop::UserEventPlaceholder>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop\runner.rs:205
  29: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::wait_and_dispatch_message<i_slint_backend_winit::SlintUserEvent>
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:419
  30: winit::platform_impl::windows::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::Ev
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform_impl\windows\event_loop.rs:259
  31: winit::platform::run_on_demand::impl$0::run_on_demand<i_slint_backend_winit::SlintUserEvent,winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::closure_env$0<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slin
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:89
  32: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand<winit::event_loop::EventLoop<i_slint_backend_winit::SlintUserEvent>,i_slint_backend_winit::event_loop::ActiveEventLoopSetterDuringEventProcessing<ref_mut$<i_slint_backend_winit::eve
             at C:\Users\redacted\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winit-0.30.5\src\platform\run_on_demand.rs:75
  33: i_slint_backend_winit::event_loop::EventLoopState::run   
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\winit\event_loop.rs:684    
  34: i_slint_backend_winit::impl$2::run_event_loop
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\winit\lib.rs:383
  35: slint::run_event_loop::closure$0
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\api\rs\slint\lib.rs:239
  36: i_slint_backend_selector::with_platform::closure$0<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\selector\lib.rs:137        
  37: i_slint_core::context::with_global_context::closure$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::a
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\context.rs:78
  38: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::try_with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:283
  39: std::thread::local::LocalKey<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext> >::with<once_cell::unsync::OnceCell<i_slint_core::context::SlintContext>,i_slint_core::context::with_global_context::closure_env$0<enum2$<core::result::Result<tup
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\std\src\thread\local.rs:260
  40: i_slint_core::context::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_global_context::closure_env$0<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::Platfor
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\core\context.rs:77
  41: i_slint_backend_selector::with_global_context<enum2$<core::result::Result<tuple$<>,enum2$<i_slint_core::api::PlatformError> > >,i_slint_backend_selector::with_platform::closure_env$0<tuple$<>,slint::run_event_loop::closure_env$0> >
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\selector\lib.rs:144        
  42: i_slint_backend_selector::with_platform<tuple$<>,slint::run_event_loop::closure_env$0>
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\internal\backends\selector\lib.rs:137        
  43: slint::run_event_loop
             at C:\Users\redacted\.cargo\git\checkouts\slint-8153123e5dffa129\787e13b\api\rs\slint\lib.rs:239
  44: redacted::main
             at .\src\main.rs:23
  45: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` 
for a verbose backtrace.

I'm really running your new code: I deleted Cargo.lock, ran cargo clean, and checked the timers.rs source when clicking on the file path from the panic message in VS Code.

@Enyium
Copy link
Contributor Author

Enyium commented Oct 11, 2024

I encountered another bug where a timer ID wasn't found: Timer::stop() didn't do anything, and the timer just continued being fired regularly, with Timer::running() directly after Timer::stop() returning true.

Timer::stop() calls this function from timers.rs (v1.8.0 code):

    fn deactivate_timer(&mut self, id: usize) {
        let mut i = 0;
        while i < self.active_timers.len() {
            if self.active_timers[i].id == id {
                self.active_timers.remove(i);
                self.timers[id].running = false;
                break;
            } else {
                i += 1;
            }
        }
    }

When debugging stepwise, I found out the loop in deactivate_timer() didn't find the timer to stop. In one case, the id parameter was 2, self.active_timers.len() was 1, and self.active_timers[i].id was 3.

@tronical
Copy link
Member

Yes indeed, I can see how this could happen. This is - in essence - the same as the other two issues I noticed: during timer callback invocation the active_timers data structure is in an inconsistent state.

Trying to stop a future timer from within an activated timer callback triggers this, as stop() fails to locate the timer in the just emptied active_timers.

I'll fix this on Monday. Before invoking any callbacks we must make sure that the data structures are in a consistent ready-for-anything state.

@tronical
Copy link
Member

I pushed a fix for this stop() issue to the branch. Could you try and see if that helps? I think that this could also help with the invalid key issue.

@Enyium
Copy link
Contributor Author

Enyium commented Oct 14, 2024

I was able to branch out app states that allow me to trigger all problems with the unpatched Slint code (invalid key, Timer::stop() not stopping, and assertion failed: !timer.being_activated).

With your branch in its current state:

  • Timer::stop() now really stops.
  • I couldn't trigger invalid key anymore for now.
  • With your previous changes, I already couldn't trigger assertion failed: !timer.being_activated anymore. This continues to be true.

@tronical
Copy link
Member

Looks like we got all of the issues then. Thank you so much for testing and the quick responses! I'll prepare a PR, after doing some cleanup.

NigelBreslaw pushed a commit that referenced this issue Oct 15, 2024
- When stopping a running but not yet expired timer from within the activation callback of an expired timer, the stopping would fail to find the timer in the active_timers list because it was built on the fly. Similarly, restarting a future timer form within the same kind of callback would end up registering the active timer twice. Fix this by doing all the active_timer re-setup before activating any callbacks, so that by the time of activation the data structure is in a good state.
- When two timers expire at the same time and from the callback of the first, the second timer would be dropped/deleted, the timer's `being_activated` was overwritten and the timer was deleted too early, causing a panic. Fix this by preserving the removal state.

Fixes #6187
Fixes #6505
@ogoffart ogoffart removed the need triaging Issue that the owner of the area still need to triage label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:tool classes & property system runtime core classes (SharedVector,SharedString) and property system (mO,bS) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants