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

FactoryVecDeque crash after clear and push #64

Closed
euclio opened this issue Dec 31, 2021 · 2 comments
Closed

FactoryVecDeque crash after clear and push #64

euclio opened this issue Dec 31, 2021 · 2 comments

Comments

@euclio
Copy link
Member

euclio commented Dec 31, 2021

If you modify the factory_advanced example like so:

diff --git a/relm4-examples/examples/factory_advanced.rs b/relm4-examples/examples/factory_advanced.rs
index 0dbae91..287b471 100644
--- a/relm4-examples/examples/factory_advanced.rs
+++ b/relm4-examples/examples/factory_advanced.rs
@@ -41,7 +41,10 @@ impl AppUpdate for AppModel {
                 });
             }
             AppMsg::RemoveLast => {
-                self.counters.pop_back();
+                self.counters.clear();
+                self.counters.push_front(Counter {
+                    value: 0,
+                });
             }
             AppMsg::CountAt(weak_index) => {
                 if let Some(index) = weak_index.upgrade() {

Then click on "add" twice and then "remove", the application will crash with the following stack trace:

thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', /home/euclio/repos/relm4/src/factory/collections/factory_vec_deque.rs:331:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
   2: core::panicking::panic_bounds_check
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:76:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index_mut
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/slice/index.rs:190:14
   4: core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/slice/index.rs:26:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::IndexMut<I>>::index_mut
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/alloc/src/vec/mod.rs:2508:9
   6: relm4::factory::collections::factory_vec_deque::FactoryVecDeque<Data>::compile_changes
             at /home/euclio/repos/relm4/src/factory/collections/factory_vec_deque.rs:331:13
   7: <relm4::factory::collections::factory_vec_deque::FactoryVecDeque<Data> as relm4::factory::Factory<Data,View>>::generate
             at /home/euclio/repos/relm4/src/factory/collections/factory_vec_deque.rs:347:26
   8: <factory_advanced::AppWidgets as relm4::traits::Widgets<factory_advanced::AppModel,()>>::view
             at ./examples/factory_advanced.rs:216:9
   9: relm4::app::RelmApp<Model>::with_app::{{closure}}
             at /home/euclio/repos/relm4/src/app.rs:83:17
  10: glib::main_context_channel::dispatch
             at /home/euclio/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-0.14.8/src/main_context_channel.rs:242:20
  11: g_main_context_dispatch
  12: <unknown>
  13: g_main_context_iteration
  14: g_application_run
  15: <O as gio::application::ApplicationExtManual>::run_with_args
             at /home/euclio/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.14.8/src/application.rs:30:13
  16: <O as gio::application::ApplicationExtManual>::run
             at /home/euclio/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.14.8/src/application.rs:23:9
  17: relm4::app::RelmApp<Model>::run
             at /home/euclio/repos/relm4/src/app.rs:37:9
  18: factory_advanced::main
             at ./examples/factory_advanced.rs:231:5
  19: core::ops::function::FnOnce::call_once
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected behavior: the app does not crash. All existing counters are removed and a new counter is added.

@AaronErhardt
Copy link
Member

Should be fixed with 7933cd6. The fix should even yield a small performance improvement.

@euclio
Copy link
Member Author

euclio commented Jan 1, 2022

Thanks for the quick fix!

@euclio euclio closed this as completed Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants