Problems with gtk-rs


#1

I have some problems with gtk-rs crate.
This is my first “serious” project with a GUI.
This is my program: https://git.savannah.nongnu.org/cgit/lcs.git/tree/src/main.rs
The main problem is that I get a segmentation fault if i do the following:

  • Open a dialog
  • Close the dialog
  • Open the dialog again
  • Click anywhere in the opened dialog

On the third operation I can read these error messages in my terminal window:

(.:10023): Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

(.:10023): Gtk-CRITICAL **: gtk_label_set_markup: assertion 'GTK_IS_LABEL (label)' failed

(.:10023): Gtk-CRITICAL **: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(.:10023): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(.:10023): Gtk-CRITICAL **: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed

(.:10023): Gtk-CRITICAL **: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed

(.:10023): Gtk-CRITICAL **: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed

(.:10023): Gtk-CRITICAL **: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

(.:10023): Gtk-CRITICAL **: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed

(.:10023): Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed

and the new created dialog is all white and empty.

Thank you for your help!


#2

First, sorry you’ve been running into problems. If you have issues like this, I’d recommend you try hopping on the Gitter for gtk-rs as you’ll probably find better support than asking here.

As to your real issue, are you able to run any of the examples properly, like ones that end up utilizing similar functionality to what you’re trying to replicate? I haven’t used any of the Glade stuff with gtk-rs, but I’ve done dialogs and windows and not seen any problems. Is there anyway you could create a minimal test case and then post the code and a description of the issue to the gtk-rs bugtracker? That’d be the fastest way to resolve this probably.


#3

Instead destroying dialog on close just hide it


#4

I prefer the forum because if anyone else runs into the same problems he can find the solution.

If I try to compile it I get the following compilation errors:

/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:151:9: 151:43 error: a type named `WindowHints` has already been imported in this module [E0252]
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:151 pub use ffi::GdkWindowHints as WindowHints;
                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24:9: 24:17 note: previous import of `WindowHints` here
/home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24 pub use auto::*;
                                                                                                ^~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:151:9: 151:43 help: run `rustc --explain E0252` to see a detailed explanation
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:136:9: 136:39 error: a type named `EventMask` has already been imported in this module [E0252]
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:136 pub use ffi::GdkEventMask as EventMask;
                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24:9: 24:17 note: previous import of `EventMask` here
/home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24 pub use auto::*;
                                                                                                ^~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:136:9: 136:39 help: run `rustc --explain E0252` to see a detailed explanation
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:134:9: 134:41 error: a type named `DragAction` has already been imported in this module [E0252]
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:134 pub use ffi::GdkDragAction as DragAction;
                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24:9: 24:17 note: previous import of `DragAction` here
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:24 pub use auto::*;
                                                                                                ^~~~~~~~
/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-0.5.2/src/lib.rs:134:9: 134:41 help: run `rustc --explain E0252` to see a detailed explanation

One problem is that the close button is automatically connected with the destroy() method, so I think that this could be a bug.

On the other hand, if the dialog is like the “about” it’s ok hiding and showing it, because it’s always the same, but if it’s an interactive dialog I need to clean up all in order to show a clean dialog, so I would prefer destroying it and creating a new one.


#8

The compilation errors were due to the old version of the rust compiler I was using. Anyway the segmentation fault problem remains if I destroy the dialogs.


#9

If you want creating new dialog IMHO you need create it from new builder that better have own glade to minimize memory consumption.
Also instead manual cloning you can use macro https://github.com/gtk-rs/examples/blob/master/src/cairo_threads.rs#L17-L33

fn run_add_light_dialog(glade_src: &str)
{
    let builder = Builder::new();
    builder.add_from_string(glade_src).unwrap();

    let tmp_dialog: Dialog = builder.get_object("add_light_dialog").unwrap();
    let tmp_d = tmp_dialog.clone();
    tmp_dialog.connect_close(move |_|{
        tmp_d.destroy();
    });
    let tmp_d = tmp_dialog.clone();
    builder.get_object::<Button>("add_light_cancel").unwrap().connect_clicked(move |_| {
    println!("on_cancel");
        tmp_d.destroy();
    });

    let first_ch_adj: Adjustment = builder.get_object("adjustment1").unwrap();
    let num_of_chs: Adjustment = builder.get_object("adjustment2").unwrap();
    let name: Entry = builder.get_object("light_name").unwrap();
    //let u2 = u.clone();
    let tmp_d = tmp_dialog.clone();
    builder.get_object::<Button>("add_light_ok").unwrap().connect_clicked(move |_| {
    println!("on_ok");
        add_light(name.clone(), first_ch_adj.clone(), num_of_chs.clone());
        tmp_d.destroy();
    });

    tmp_dialog.run();
}

#10

Yes, I think I’ll do something like that. Thank you very much!