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

Crash when using an action callback with its args #33

Closed
sqp opened this issue Aug 28, 2021 · 4 comments
Closed

Crash when using an action callback with its args #33

sqp opened this issue Aug 28, 2021 · 4 comments
Labels
bug Changes to fix bugs that do not require refactoring

Comments

@sqp
Copy link

sqp commented Aug 28, 2021

I'm trying the new menu features and wanted to register a callback with its args when I encountered a strange bug

	isMaximized := appInfo.Win.IsMaximized()
	action_fullscreen := gio.NewSimpleActionStateful("fullscreen", nil, glib.NewVariantBoolean(isMaximized))
	action_fullscreen.Connect("change-state", func(action *gio.SimpleAction, value *glib.Variant) {
		fmt.Println("menu action_fullscreen")
	})
	appInfo.Win.AddAction(action_fullscreen)

When I click on the related menu button, it panics when trying to recast the object to the same(?) type:

panic: reflect.Value.Convert: value of type *glib.Variant cannot be converted to type *glib.Variant [recovered]
panic: closure error: unexpected panic caught: reflect.Value.Convert: value of type *glib.Variant cannot be converted to type *glib.Variant

The line that fail (glib.go:208) :

args = append(args, reflect.ValueOf(val).Convert(fsType.In(i)))

I added some output to see what's happening

println(reflect.TypeOf(val).String(), fsType.In(i).String(), reflect.TypeOf(val) == fsType.In(i))

that prints just before the crash.

*gio.SimpleAction *gio.SimpleAction true
*glib.Variant *glib.Variant false

The *gio.SimpleAction is nicely recognized and recasted, but there seem to be some mystery with the *glib.Variant
If needed, here's the C code I'm using as example
and my imports :

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

(damn 24 min to recompile the whole glib+gtk on my old i7 proc)

@diamondburned
Copy link
Owner

As far as glib.Variant goes, you need to import
github.com/diamondburned/gotk4/pkg/core/glib for it, because the GVariant
code was primarily hand-written.

The most straightforward solution to fix this confusion would be to have a
generation edge case, but currently, the library only allows ignoring the type
during both generation and resolving, and edge cases to that must be hard-coded
in the type resolver.

As a sidenote, just compiling GTK4 by itself should be faster, since GTK3 takes
longer to compile. You could also try applying certain Go patches listed in
.nix/overlay.nix that tries to multithread the Cgo build process.

@diamondburned diamondburned added the bug Changes to fix bugs that do not require refactoring label Oct 6, 2021
@diamondburned
Copy link
Owner

As of commit 579eec99a, callbacks should be using pkg/glib/v2.Variant instead of pkg/core/glib.Variant.

I'll be closing this issue since it's kind of fixed.

@diamondburned
Copy link
Owner

Reopening since the commit didn't actually work. I'll fix it in a minute.

@diamondburned diamondburned reopened this Jan 31, 2022
@diamondburned
Copy link
Owner

Fixed in b63160e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Changes to fix bugs that do not require refactoring
Projects
None yet
Development

No branches or pull requests

2 participants