Open awused opened 5 months ago
I don't think the cause of whatever issue you are facing is caused by the bindings. A good way to ensure that is to write a similar code to reproduce the issue in C.
I did attempt to do the same thing in C in gtk-demo, as I said in the bug report, but the refcounts appear correct. Maybe you can see where my attempted C reproduction is different from that gtk4-rs is doing.
Bug description
This is an unusual one. I have some code that was grabbing the grandparents of columnview listcell entries so that I could use them for dragging and drop, since painting a single cell looked bizarre. It worked fine in GTK 4.10, but with 4.12 gtk-rs in particular breaks.
Just calling
drop(child.parent().unwrap().parent())
crashes the application by inadvertently freeing the last reference tochild
's grandparent, which is obviously wrong and should never happen.I am not completely certain this is a gtk-rs bug, but I've tried reproducing this with similar code against gtk itself in C (manually using ref/unref, so if the problem was objects being created with 0 refcount I would have triggered it), and I could not reproduce it despite trying multiple ways.
Reproduction
Apply the patch to
examples/column_view_datagrid/main.rs
and run withcargo run --bin column_view_datagrid
against gtk4.12.The output I get is honestly bizarre. Notably the grandparent refcount is 1, not 2, so as soon as
gp
is dropped the grandparent GtkColumnViewRowWidget is disposed, which breaks everything going forward. The timeout seems necessary as if I exclude it the breakage doesn't happen. Without the timeout, the grandparent refcount is properly 2 in these logs.Grandparent Widget { inner: TypedObjectRef { inner: 0x55ee326f37b0, type: GtkColumnViewRowWidget } }, refcount: 1
should have a refcount of 2, not 1.Backtrace
This is a segfault, and the gdb output isn't terribly interesting either.
patch here
``` diff --git a/examples/column_view_datagrid/main.rs b/examples/column_view_datagrid/main.rs index 90c877f2a0..8c2cbf6bdf 100644 --- a/examples/column_view_datagrid/main.rs +++ b/examples/column_view_datagrid/main.rs @@ -33,11 +33,14 @@ fn build_ui(application: >k::Application) { let store = gio::ListStore::new::