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

Add example on how to use Gio::ListModel to populate widgets. #62

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

hugopl
Copy link
Owner

@hugopl hugopl commented Nov 20, 2023

This example is now crashing, at some point it worked fine, I'm not sure it was a change in GTK libraries that exposed a bug in GICrystal or something else.

Anyway... the crash seems to happen at the interface cast, I experienced issues with interface casts before, I'll let this example here just in case someone are interested in find the issue.

This crash is probably related to why new builds of RTFM also crashes while the old build I have here, with same code as before works.

@hugopl hugopl force-pushed the list-model-example branch from 9aaf698 to 400a168 Compare November 20, 2023 14:37
@hugopl
Copy link
Owner Author

hugopl commented Nov 21, 2023

Problem found, I'll write it down here so I don't forget.

GICrystal stores the pointer of the Crystal wrapper into the GObject using https://docs.gtk.org/gobject/method.Object.set_qdata.html, so later if the GObject appears it will try to re-use this wrapper if it still exists, this is an optimization for Pure wrappers and a need for Crystal objects that inherit GObject.

However... this optimization is crashing things. If the object first appears as a GObject on Crystal world, it will create a GObject wrapper and store its pointer into GObject C object.

Later we cast this object to its real type, Gtk::ListView in the example, so GICrystal looks at the qdata in the C GObject and retrieves the Crystal wrapper, thinking it's all ok it just do a unsafe cast. Later when you try to use a ListView method in this object it will crash, because it's a Object, not a ListView in Crystal code.

Removing the cache works.

@hugopl
Copy link
Owner Author

hugopl commented Nov 21, 2023

This example works with hugopl/gi-crystal#133

@hugopl
Copy link
Owner Author

hugopl commented Nov 21, 2023

BTW the example is failing on CI because of https://gitlab.gnome.org/GNOME/gtk/-/commit/be1729b316da53f12ccc16dc925c563acc2fb4c1

i.e. an old version of SignalListItemFactory used ListItem type instead of GObject in parameters, but it was changed because there are plans to use these factory with other kind of objects.

I'll add a monkey patch in the example itself to deal with this CI situation... or wait until Ubuntu updates their packages.

@hugopl hugopl force-pushed the list-model-example branch from 400a168 to bbce167 Compare November 21, 2023 21:09
@hugopl hugopl merged commit bc3431d into main Nov 21, 2023
2 checks passed
@hugopl hugopl deleted the list-model-example branch November 30, 2023 21:46
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

Successfully merging this pull request may close these issues.

1 participant