gtk-rs / gtk4-rs

Rust bindings of GTK 4
https://gtk-rs.org/gtk4-rs/
MIT License
1.75k stars 168 forks source link

The target object of type SqueezerBin has no writable property called 'keep-aspect-ratio' #1757

Closed mtilda closed 1 month ago

mtilda commented 1 month ago

I am using GTK 4.10.4 on Ubuntu 23.04.

Bug description

When I clone this repo, cd into the directory examples, and run cargo run --bin squeezer_bin, the program panics with the following error.

(squeezer_bin:57360): GLib-GObject-CRITICAL **: 20:06:32.727: ../../../gobject/gbinding.c:1323: The target object of type SqueezerBin has no writable property called 'keep-aspect-ratio'
thread 'main' panicked at 'assertion failed: !ptr.is_null()', /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/glib/src/gobject/auto/binding.rs:7:1

Backtrace

You can get the backtrace running your program with the environment variable RUST_BACKTRACE=full.

   0:     0x5570ac33292a - std::backtrace_rs::backtrace::libunwind::trace::h8e4625bf1ac31a88
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x5570ac33292a - std::backtrace_rs::backtrace::trace_unsynchronized::h421f1f634f0892c1
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5570ac33292a - std::sys_common::backtrace::_print_fmt::h3f182e54791f5448
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x5570ac33292a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf068f2595d6423bc
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x5570ac361c6f - core::fmt::write::h8a6836b78d5c6e17
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/fmt/mod.rs:1254:17
   5:     0x5570ac33ac15 - std::io::Write::write_fmt::h17261d82783cf239
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/io/mod.rs:1698:15
   6:     0x5570ac3326e5 - std::sys_common::backtrace::_print::h47e0330b564519b3
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x5570ac3326e5 - std::sys_common::backtrace::print::h1e9ac5d07b7c6802
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x5570ac33879e - std::panicking::default_hook::{{closure}}::hc9f7049681adefa1
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:269:22
   9:     0x5570ac338459 - std::panicking::default_hook::h9b6c36113da327db
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:288:9
  10:     0x5570ac338cf1 - std::panicking::rust_panic_with_hook::hc985a07c4d135a7a
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:691:13
  11:     0x5570ac332c12 - std::panicking::begin_panic_handler::{{closure}}::heb31d97adfbed1ba
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:580:13
  12:     0x5570ac332a36 - std::sys_common::backtrace::__rust_end_short_backtrace::h36966c6ea18decae
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x5570ac3389f2 - rust_begin_unwind
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:578:5
  14:     0x5570ac2e72a3 - core::panicking::panic_fmt::h42c1b10c64151f1e
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/panicking.rs:67:14
  15:     0x5570ac2e733d - core::panicking::panic::hd3becb37bf39c010
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/panicking.rs:117:5
  16:     0x5570ac31287b - <glib::gobject::auto::binding::Binding as glib::translate::FromGlibPtrNone<*mut gobject_sys::GBinding>>::from_glib_none::h1eeaa90b6075f311
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/glib/src/object.rs:881:17
  17:     0x5570ac3150fa - glib::translate::from_glib_none::h90e8524e5d97b8a1
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/glib/src/translate.rs:1625:5
  18:     0x5570ac3202b4 - glib::object::BindingBuilder::build::h0ad0774af051444c
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/glib/src/object.rs:3826:13
  19:     0x5570ac2f8aeb - squeezer_bin::main::{{closure}}::hd15ede8a80ff3dd5
                               at /REDACTED/repos/gtk4-rs/examples/squeezer_bin/main.rs:22:9
  20:     0x5570ac2f8fcf - gio::auto::application::ApplicationExt::connect_activate::activate_trampoline::h6852c0a6dcb8815e
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/gio/src/auto/application.rs:458:13
  21:     0x7f64b5bc3010 - g_closure_invoke
  22:     0x7f64b5bf03d6 - <unknown>
  23:     0x7f64b5be069a - g_signal_emit_valist
  24:     0x7f64b5be0923 - g_signal_emit
  25:     0x7f64b5ced978 - <unknown>
  26:     0x7f64b5cedb68 - g_application_run
  27:     0x5570ac2ecebe - gio::application::ApplicationExtManual::run_with_args::haff52543ce790462
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/gio/src/application.rs:29:13
  28:     0x5570ac2ecfd9 - gio::application::ApplicationExtManual::run::h93cf2942eb6b5a7c
                               at /REDACTED/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/4bc38db/gio/src/application.rs:22:9
  29:     0x5570ac2fe63c - squeezer_bin::main::h4d494561b3ea17a9
                               at /REDACTED/repos/gtk4-rs/examples/squeezer_bin/main.rs:31:5
  30:     0x5570ac2ff15b - core::ops::function::FnOnce::call_once::h80a9291ba56b6bfd
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/ops/function.rs:250:5
  31:     0x5570ac2f903e - std::sys_common::backtrace::__rust_begin_short_backtrace::hce037a074503b3f8
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/sys_common/backtrace.rs:134:18
  32:     0x5570ac2eef21 - std::rt::lang_start::{{closure}}::ha5c7a7a5934afc6c
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/rt.rs:166:18
  33:     0x5570ac3388f1 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha9f60dade5077694
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/core/src/ops/function.rs:287:13
  34:     0x5570ac3388f1 - std::panicking::try::do_call::h63bff77c0ba43647
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:485:40
  35:     0x5570ac3388f1 - std::panicking::try::h8692005afaedc924
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:449:19
  36:     0x5570ac3388f1 - std::panic::catch_unwind::he0ac74c036d944be
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panic.rs:140:14
  37:     0x5570ac3388f1 - std::rt::lang_start_internal::{{closure}}::he183b3f523a43372
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/rt.rs:148:48
  38:     0x5570ac3388f1 - std::panicking::try::do_call::hd9b70b7caced9e80
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:485:40
  39:     0x5570ac3388f1 - std::panicking::try::h11669f963cae659c
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panicking.rs:449:19
  40:     0x5570ac34766b - std::panic::catch_unwind::hf0ae1c6bfca2fd90
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/panic.rs:140:14
  41:     0x5570ac34766b - std::rt::lang_start_internal::h0612c8133b44328f
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/rt.rs:148:20
  42:     0x5570ac2eeefa - std::rt::lang_start::hecd8eea800658988
                               at /build/rustc-TlvO7Q/rustc-1.70.0+dfsg0ubuntu1~bpo2/library/std/src/rt.rs:165:17
  43:     0x5570ac2fe69e - main
  44:     0x7f64b5823a90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  45:     0x7f64b5823b49 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  46:     0x5570ac2e7755 - _start
  47:                0x0 - <unknown>
mtilda commented 1 month ago

I have also tried running the command with --features v4_10 and gotten the same result.

mtilda commented 1 month ago

When I comment out these lines:

https://github.com/gtk-rs/gtk4-rs/blob/3826b9acf320beedc3a1b0a326501e8ebadc05e6/examples/squeezer_bin/main.rs#L22-L24

The window appears empty:

image

I am unsure if the squeezer (SqueezerBin::default()) is not mounting or if its child (Some(&gtk::Label::new(Some("Hello World!")))) is not mounting. I'm pretty new to GTK, so I'm unsure how to debug this.

mtilda commented 1 month ago

Setting GTK_DEBUG=all lets me run the program with an interactive debugging window, and I can see the GtkLabel object with the value "Hello World!" that is a child of the SqueezerBin object.

image

Further reading: Running and debugging GTK Applications

mtilda commented 1 month ago

Not sure if this is relevant, but it looks like the property GtkPicture:keep-aspect-ratio was deprecated in GTK 4.8 in favor of the new property GtkPicture:content-fit.

I do not see either of those properties documented on GtkWidget.

It makes sense to me that we are trying to define this as a custom property on SqueezerBin, but I am not sure where we are going wrong.

mtilda commented 1 month ago

I believe I have identified the reason the GtkLabel is not visible even when disabling the code that is causing errors...

SqueezerBin::size_allocate() has a mistake:

https://github.com/gtk-rs/gtk4-rs/blob/3826b9acf320beedc3a1b0a326501e8ebadc05e6/examples/squeezer_bin/squeezer_bin/imp.rs#L55

When we call child_size, we should be passing &child, not &*widget:

@@ -52,7 +52,7 @@ impl WidgetImpl for SqueezerBin {
     fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
         let widget = self.obj();
         if let Some(child) = widget.child() {
-            let ((_, horizontal_size), (_, vertical_size)) = child_size(&*widget);
+            let ((_, horizontal_size), (_, vertical_size)) = child_size(&child);

             let (mut horizontal_zoom, mut vertical_zoom) = (
                 width as f32 / horizontal_size as f32,
bilelmoussaoui commented 1 month ago

I will have a look in a bit

sdroege commented 1 month ago

It was fixed by https://github.com/gtk-rs/gtk4-rs/pull/1760

bilelmoussaoui commented 1 month ago

No it wasn't actually