slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.54k stars 600 forks source link

Listview crash when update model #2780

Closed heng30 closed 1 year ago

heng30 commented 1 year ago

When I update Listview model datas, the program crash. Here is the Rust backtrace:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/blue/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-core-1.0.0/model.rs:963:77
stack backtrace:
   0:     0x55684debc9ea - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55684debc9ea - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55684debc9ea - std::sys_common::backtrace::_print_fmt::hbc6ebcfb2910b329
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x55684debc9ea - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he1c117e52d53614f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55684dee33be - core::fmt::write::h25eb51b9526b8e0c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/fmt/mod.rs:1213:17
   5:     0x55684deb6e85 - std::io::Write::write_fmt::ha9edec5fb1621933
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/io/mod.rs:1682:15
   6:     0x55684debc7b5 - std::sys_common::backtrace::_print::hf8657cd429fc3452
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x55684debc7b5 - std::sys_common::backtrace::print::h41b9b18ed86f86bd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x55684debdf9f - std::panicking::default_hook::{{closure}}::h22a91871f4454152
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:267:22
   9:     0x55684debdcdb - std::panicking::default_hook::h21ddc36de0cd4ae7
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:286:9
  10:     0x55684debe6a9 - std::panicking::rust_panic_with_hook::h5059419d6d59b3d0
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:688:13
  11:     0x55684debe402 - std::panicking::begin_panic_handler::{{closure}}::h0f383c291cd78343
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:577:13
  12:     0x55684debce9c - std::sys_common::backtrace::__rust_end_short_backtrace::h70ab22f2ad318cdd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:137:18
  13:     0x55684debe152 - rust_begin_unwind
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
  14:     0x55684d230923 - core::panicking::panic_fmt::hd1d46bcde3c61d72
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
  15:     0x55684d2309bd - core::panicking::panic::h056c466ab4571cf2
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:114:5
  16:     0x55684d4c96c1 - i_slint_core::model::Repeater<C>::ensure_updated_listview::h885ebdc85a5676a8
  17:     0x55684d47a787 - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::visit_dynamic::h88365ed6f163e547
  18:     0x55684d4ea20f - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  19:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  20:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  21:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  22:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  23:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  24:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  25:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  26:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  27:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  28:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  29:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  30:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  31:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  32:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  33:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  34:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  35:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  36:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  37:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  38:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  39:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  40:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  41:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  42:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  43:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  44:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  45:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  46:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  47:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  48:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  49:     0x55684d4e890e - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  50:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  51:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  52:     0x55684dbf7a7f - i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item::hc209a8e3909a0c71
  53:     0x55684d4ea279 - i_slint_core::item_tree::visit_item_tree::{{closure}}::h48e3158589d479a3
  54:     0x55684d4e8947 - i_slint_core::item_tree::visit_item_tree::h8629dee0030fa2f3
  55:     0x55684d47a58a - <chatbox::slint_generatedAppWindow::InnerAppWindow as i_slint_core::component::Component_vtable_mod::Component>::visit_children_item::h95d6d3e97eff38fc
  56:     0x55684d4aaa5d - <chatbox::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::visit_children_item::hf65218ca0cbecb4e
  57:     0x55684dbf76d1 - i_slint_core::item_rendering::render_component_items::h1665f17ffceb7ace
  58:     0x55684db6fb13 - i_slint_backend_qt::qt_window::QtWindow::paint_event::{{closure}}::h7dd921888766882d
  59:     0x55684db6d9ca - i_slint_core::properties::PropertyTracker<DirtyHandler>::evaluate_as_dependency_root::h4a03ae12637eee1f
  60:     0x55684db6a09e - Slint_paintEvent
  61:     0x55684db88a5b - _ZN11SlintWidget10paintEventEP11QPaintEvent
  62:     0x7f8c9d1af514 - _ZN7QWidget5eventEP6QEvent
  63:     0x7f8c9d178b5c - _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
  64:     0x7f8c9e28e028 - _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent
  65:     0x7f8c9d1a33eb - _ZN14QWidgetPrivate14sendPaintEventERK7QRegion
  66:     0x7f8c9d1a47b6 - _ZN14QWidgetPrivate10drawWidgetEP12QPaintDeviceRK7QRegionRK6QPoint6QFlagsINS_14DrawWidgetFlagEEP8QPainterP21QWidgetRepaintManager
  67:     0x7f8c9d184890 - <unknown>
  68:     0x7f8c9d1af1e4 - _ZN7QWidget5eventEP6QEvent
  69:     0x7f8c9d178b5c - _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
  70:     0x7f8c9e28e028 - _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent
  71:     0x7f8c9e28eb33 - _ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData
  72:     0x7f8c9e2d4f58 - <unknown>
  73:     0x7f8c9c50f53b - g_main_context_dispatch
  74:     0x7f8c9c56c219 - <unknown>
  75:     0x7f8c9c50e1a2 - g_main_context_iteration
  76:     0x7f8c9e2d8d3c - _ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE
  77:     0x7f8c9e28668c - _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE
  78:     0x7f8c9e2912f9 - _ZN16QCoreApplication4execEv
  79:     0x55684db747cf - <i_slint_backend_qt::Backend as i_slint_core::platform::Platform>::run_event_loop::h35e378381392b754
  80:     0x55684d80a28e - std::thread::local::LocalKey<T>::with::h1a45ed8ca740e58b
  81:     0x55684d80a200 - slint::run_event_loop::hf7e4025b198e8243
  82:     0x55684d483111 - <chatbox::slint_generatedAppWindow::AppWindow as i_slint_core::api::ComponentHandle>::run::h127827d014c7ccb2
  83:     0x55684d4e6e22 - chatbox::main::{{closure}}::h5af230eff30329d8
  84:     0x55684d4df1ae - tokio::runtime::park::CachedParkThread::block_on::h3d69f33a4ddb667b
  85:     0x55684d533368 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h14ba433b0259ed38
  86:     0x55684d54d216 - tokio::runtime::runtime::Runtime::block_on::h897605e4b7db5220
  87:     0x55684d4fcd81 - chatbox::main::h9dcc30bd2b2f39e2
  88:     0x55684d599e13 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21ab922df9c6de99
  89:     0x55684d545949 - std::rt::lang_start::{{closure}}::ha387c1a8f2bcf1ae
  90:     0x55684deb0c4c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h203afb3af230319a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/ops/function.rs:287:13
  91:     0x55684deb0c4c - std::panicking::try::do_call::hf68e87013b70f3c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:483:40
  92:     0x55684deb0c4c - std::panicking::try::h040ea8f298390ba2
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:447:19
  93:     0x55684deb0c4c - std::panic::catch_unwind::h1e17b198887a05fa
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs:140:14
  94:     0x55684deb0c4c - std::rt::lang_start_internal::{{closure}}::hfb902d8927e51b86
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs:148:48
  95:     0x55684deb0c4c - std::panicking::try::do_call::h354e6eb41f2e7d42
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:483:40
  96:     0x55684deb0c4c - std::panicking::try::h4a39749cd018228c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:447:19
  97:     0x55684deb0c4c - std::panic::catch_unwind::h30bce83b8de61cca
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs:140:14
  98:     0x55684deb0c4c - std::rt::lang_start_internal::h8f7e70b1a2558118
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs:148:20
  99:     0x55684d4fce45 - main
 100:     0x7f8c9ce3c790 - <unknown>
 101:     0x7f8c9ce3c84a - __libc_start_main
 102:     0x55684d230fb5 - _start
 103:                0x0 - <unknown>
QPainter::end: Painter ended with 9 saved states
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt.
You must not let any exception whatsoever propagate through Qt code.
If that is not possible, in Qt 5 you must at least reimplement
QCoreApplication::notify() and catch all exceptions there.
hunger commented 1 year ago

Do you have a small example to reproduce this?

How do you try to update the model?

You seem to be using the Qt backend, but which OS do you run on?

heng30 commented 1 year ago

I use archlinux.

I don't have a small example. This issue produce after i update three listview models, it produce randomly and hard to reproduce.

you can find the source code in https://github.com/Heng30/chatbox/blob/main/chatbox/src/logic/session.rs, when execute the ui.global::<Logic>().on_switch_session() function, the program has a low probability crash. I think the issue caused by ui.global::<Logic>().invoke_show_session_archive_list(new_uuid.clone()); or maybe not.

I generate a new model and replace the old one to update the model.

heng30 commented 1 year ago

If I push the ui.global::<Logic>().invoke_show_session_archive_list(new_uuid.clone()); in a timer to update the model after delay. The issue seem to be fixed.

ogoffart commented 1 year ago

I cloned your code and try to reproduce it, but I don't know how to reproduce it since i don't know what to do to make it crash (and not speaking the language doesn't help)

Anyway, the unwrap occurs when accessing the model in this line:

 c.1.as_ref().unwrap().update(new_offset, model.row_data(new_offset).unwrap());

Presumably the second unwrap is falling because the model return None. Either we do something wrong and new_offset is somehow outside of the range, or something else fishy is going on.

I'll try to make it a better error message

ogoffart commented 1 year ago

Actually, I was able to reproduce it In a testcase. Thanks for reporting.

ogoffart commented 1 year ago

https://github.com/slint-ui/slint/pull/2822 should be fixing the issue. You can try using the git version of slint for now and see if it fixes it