diamondburned/gotk4

GTK Assertion Fails calling NewConstraint

Matir opened this issue · 3 comments

Matir commented

When trying to build a constraint via NewConstraint, a GTK assertion fails:

2023/02/17 23:55:03 Critical: Gtk: gtk_constraint_new: assertion 'target == NULL || GTK_IS_CONSTRAINT_TARGET (target)' failed

This is my attempt at a minimal reproducer:

package main

import (
	"os"

	gio "github.com/diamondburned/gotk4/pkg/gio/v2"
	gtk "github.com/diamondburned/gotk4/pkg/gtk/v4"
)

func main() {
	app := gtk.NewApplication("com.example", gio.ApplicationFlagsNone)
	app.ConnectActivate(func() {
		foo := gtk.NewLabel("foo")
		bar := gtk.NewLabel("bar")
		box := gtk.NewBox(gtk.OrientationVertical, 0)
		box.Append(foo)
		box.Append(bar)
		layout := gtk.NewConstraintLayout()
		box.SetLayoutManager(layout)
		con := gtk.NewConstraint(
			foo, gtk.ConstraintAttributeLeft, gtk.ConstraintRelationEq, box, gtk.ConstraintAttributeLeft, 1.0, 0.0, 1)
		layout.AddConstraint(con)
		win := gtk.NewApplicationWindow(app)
		win.SetTitle("ConstraintLayout test")
		win.SetChild(box)
		win.Show()
	})
	app.Run(os.Args)
}

As far as I can tell, all Widget should be valid instances of ConstraintTargeter. I notice the generated code has this very confusing type conversion to the C type, I'm afraid I'm not able to follow what's going on here:

_arg1 = *(*C.gpointer)(unsafe.Pointer(coreglib.InternObject(target).Native()))

_arg1 = *(*C.gpointer)(unsafe.Pointer(coreglib.InternObject(target).Native()))

Er, I don't think the codegen did a correct job here. Why is it dereferencing a GObject pointer?

The code generator is a mess right now, especially if you use the main branch. A lot of the code has been rusted out of my mind ever since my effort to add libgirepository into the code generator started :(

Matir commented

Is there a branch/tag you'd recommend using?

Is there a branch/tag you'd recommend using?

Other than the latest release, unfortunately not. The generator will just have to be fixed.