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

Panic with 'assertion failed: self.is::<T>()' #216

Closed
haecker-felix opened this issue Mar 14, 2021 · 5 comments
Closed

Panic with 'assertion failed: self.is::<T>()' #216

haecker-felix opened this issue Mar 14, 2021 · 5 comments

Comments

@haecker-felix
Copy link

thread 'main' panicked at 'assertion failed: self.is::<T>()', /home/haecker-felix/Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/glib/src/object.rs:275:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:50:5
   3: glib::object::Cast::unsafe_cast_ref
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/glib/src/object.rs:275:9
   4: glib::object::Cast::upcast_ref
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/glib/src/object.rs:128:18
   5: <shortwave::model::station_model::SwStationModel as core::convert::AsRef<gio::auto::list_model::ListModel>>::as_ref
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/glib/src/object.rs:966:17
   6: gtk4::auto::flow_box::FlowBox::bind_model::{{closure}}
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/4552124/gtk4/src/auto/flow_box.rs:80:31
   7: core::option::Option<T>::map
             at /usr/lib/sdk/rust-stable/lib/rustlib/src/rust/library/core/src/option.rs:453:29
   8: gtk4::auto::flow_box::FlowBox::bind_model
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/4552124/gtk4/src/auto/flow_box.rs:80:17
   9: shortwave::ui::station_flowbox::SwStationFlowBox::init
             at ./Dokumente/Projekte/Shortwave/src/ui/station_flowbox.rs:86:9
  10: shortwave::ui::pages::library_page::SwLibraryPage::setup_widgets
             at ./Dokumente/Projekte/Shortwave/src/ui/pages/library_page.rs:103:9
  11: shortwave::ui::pages::library_page::SwLibraryPage::init
             at ./Dokumente/Projekte/Shortwave/src/ui/pages/library_page.rs:88:9
  12: shortwave::ui::window::SwApplicationWindow::setup_widgets
             at ./Dokumente/Projekte/Shortwave/src/ui/window.rs:152:9
  13: shortwave::ui::window::SwApplicationWindow::new
             at ./Dokumente/Projekte/Shortwave/src/ui/window.rs:140:9
  14: shortwave::app::SwApplication::create_window
             at ./Dokumente/Projekte/Shortwave/src/app.rs:176:22
  15: <shortwave::app::SwApplicationPrivate as gio::subclass::application::ApplicationImpl>::activate
             at ./Dokumente/Projekte/Shortwave/src/app.rs:124:22
  16: gio::subclass::application::application_activate
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/gio/src/subclass/application.rs:372:5
  17: <unknown>
  18: g_signal_emit_valist
  19: g_signal_emit
  20: <unknown>
  21: <T as gio::subclass::application::ApplicationImplExt>::parent_local_command_line
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/gio/src/subclass/application.rs:232:23
  22: gio::subclass::application::ApplicationImpl::local_command_line
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/gio/src/subclass/application.rs:99:9
  23: gio::subclass::application::application_local_command_line
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/gio/src/subclass/application.rs:415:15
  24: g_application_run
  25: <O as gio::application::ApplicationExtManual>::run
             at ./Dokumente/Projekte/Shortwave/_build/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/a2568f0/gio/src/application.rs:23:13
  26: shortwave::app::SwApplication::run
             at ./Dokumente/Projekte/Shortwave/src/app.rs:171:9
  27: shortwave::main
             at ./Dokumente/Projekte/Shortwave/src/main.rs:89:5
  28: core::ops::function::FnOnce::call_once
             at /usr/lib/sdk/rust-stable/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5

I'm using commit 4552124
That code snippet worked before, that was commit c430251

    pub fn init(&self, model: SwStationModel, sender: Sender<Action>) {
        let imp = imp::SwStationFlowBox::from_instance(self);

        //let sorter = gtk::StringSorter::
        //let sortlist_model = gtk::SortListModel::new(model, sorter);

        imp.flowbox.get().bind_model(
            // 9: shortwave::ui::station_flowbox::SwStationFlowBox::init
            // at ./Dokumente/Projekte/Shortwave/src/ui/station_flowbox.rs:86:9
            Some(&model),
            clone!(@strong sender => move |station|{
                let station = station.downcast_ref::<SwStation>().unwrap();
                let row = SwStationRow::new(sender.clone(), station.clone());
                row.upcast()
            }),
        );

        self.setup_signals(sender);
    }

Complete code is available here: https://gitlab.gnome.org/World/Shortwave/-/commits/wip/haecker-felix/gtk-rs-ugprade

@sdroege
Copy link
Member

sdroege commented Mar 14, 2021

That's probably my fault, let's see...

@sdroege
Copy link
Member

sdroege commented Mar 14, 2021

The listbox_model example from gtk-rs also does not build anymore FWIW (gtk-rs/gtk3-rs#354). I assume this can be reproduced with that example, we'll see :)

@sdroege
Copy link
Member

sdroege commented Mar 14, 2021

You're missing an type Interfaces = ... here.

You can write the whole thing as follows now (note the Default deriving and the lack of fn new() also):

#[derive(Debug, Default)]
pub struct SwStationModel {
    pub vec: RefCell<Vec<SwStation>>,
}

#[glib::object_subclass]
impl ObjectSubclass for SwStationModel {
    const NAME: &'static str = "SwStationModel";
    type ParentType = glib::Object;
    type Type = super::SwStationModel;
    type Interfaces = (gio::ListModel, );
}

@sdroege sdroege closed this as completed Mar 14, 2021
@sdroege
Copy link
Member

sdroege commented Mar 14, 2021

See also the listbox_model.rs example after gtk-rs/gtk3-rs#355

@haecker-felix
Copy link
Author

Yep, that fixed it. Also thanks a lot for the hint with Default 👍

Implementing that was really satisfying :D
grafik

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