Open thatcher-gaming opened 3 weeks ago
The problem seems to be the order of creation, so when the C code calls the Crystal property the Crystal object isn't fully initialized yet.
Problem:
GICrystal stores a qdata in each GObject to inform the pointer of the Crystal object for that GObject, so when C code asks for a GObject property defined in Crystal it knows how to get it.
This qdata is set at lib/gi-crystal/src/bindings/g_object/object.cr:609
def initialize
@pointer = LibGObject.g_object_newv(self.class.g_type, 0, Pointer(LibGObject::Parameter).null)
LibGObject.g_object_ref_sink(self) if LibGObject.g_object_is_floating(self) == 1
LibGObject.g_object_set_qdata(self, GICrystal::INSTANCE_QDATA_KEY, Pointer(Void).new(object_id))
self._after_init
end
But... for templates, the GObject property is read before we reach the line 609, it's read when the GObject is created on LibGObject.g_object_newv
call. So Crystal code is asked for a property value but it has no means to know the Crystal object instance where it can get this value from.
Possible solution that I did pop up from my head but need more study:
Hi, if you could test https://github.com/hugopl/gi-crystal/pull/153 to double check if the issue was fixed I would appreciate :-)
To use this version of gi-crystal you need to use a shards.override.yml file.
@hugopl That does indeed seem to have done the trick. Many thanks for the fix!
Thanks for testing it! (and also for reporting the issue!)
Good thing about this fix is that now will also be possible to create Crystal deffined widgets from GtkBuild files :-), I didn't tested yet... but in theory it works.
I'll compile Tijolo with this patch and use it some days just to check if it's not doing anything bad before merge it.
This patch and the future patch to have signal connections that doesn't leak objects will grant a good leap in quality for these bindings.
Using a property binding from within a .ui file will result in a GICrystal::ObjectCollectedError being raised.
Here's an example:
test.ui:
Output: