Relm4 / relm4-template

Other
30 stars 7 forks source link

Opening the `AboutDialog` a second time after closing #28

Closed m4dh0rs3 closed 7 months ago

m4dh0rs3 commented 8 months ago

Opening the AboutDialog a second time after closing "will leave the window in an inconsistent state" GTK warns. I myself can't close the AboutDialog anymore, I will have to kill the app.

This happens on both profiles. Run with GNOME Builder. Does not happen with gtk-rust-template.

Reproduce:

  1. Start app
  2. Open About GTK Rust template
  3. Close the about window
  4. Open About GTK Rust template
  5. Now try and close it
Application started at 12:02:54 PM
2024-03-05T11:02:58.562026Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: new
2024-03-05T11:02:58.562046Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: enter
2024-03-05T11:02:58.568359Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: exit
2024-03-05T11:02:58.568377Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: close time.busy=6.31ms time.idle=41.5µs
2024-03-05T11:03:02.243543Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: new
2024-03-05T11:03:02.243567Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: enter
(gtk-rust-template:234556): Gtk-WARNING **: 12:03:02.243: A window is shown after it has been destroyed. This will leave the window in an inconsistent state.
2024-03-05T11:03:02.248026Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: exit
2024-03-05T11:03:02.248076Z  INFO update_with_view{input=() component="gtk_rust_template::modals::about::AboutDialog" id="0x7fff34f5aa08"}: relm4::component::sync::builder: close time.busy=4.45ms time.idle=80.8µs
^CApplication exited

Maybe related to gtk4-rs#1544, fixed in 0.8.0, which Relm4 has not updated to yet.

m4dh0rs3 commented 8 months ago

Closing, as I believe this should be fixed at Relm4 by upgrading gtk4, not at this template.

AaronErhardt commented 8 months ago

This is actually a bug in the template. If you close a GTK window, it gets destroyed by default unless you set connect_close_request() and just hide the window from there. The problem is that the variable still exists, which makes it very easy in Relm4 to reopen the already destroyed window. I actually contributed the warning message with "A window is shown after it has been destroyed..." to GTK to help (Relm4) developers spot this mistake.

To fix this, either the dialog must be recreated every time or the close-request signal must be intercepted to prevent the window from being destroyed and leaving it in an inconsistent state.

m4dh0rs3 commented 8 months ago

I fixed this by setting .set_hide_on_close(true); on my AboutWindow for now.

AaronErhardt commented 8 months ago

I fixed this by setting .set_hide_on_close(true); on my AboutWindow for now.

This is a good solution. As I said, you just need to prevent to window from being destroyed on close, which the "hide-on-close" property prevents. If you want, you could send a PR with the same change here :)

AaronErhardt commented 7 months ago

It should be fixed now with the latest commits.