grow-graphics/gd

panic when including gd.Signal

Closed this issue · 6 comments

When using a gd.Signal I get the following panic on startup of godot:

panic: gd.Variant: unsupported type gd.Signal[func()]

goroutine 17 [running, locked to thread]:
grow.graphics/gd/internal.Context.Variant({{0x7ffc354d6fa0?, 0xc0003b1800?}, 0x7ffc36738600?}, {0x7ffc354d6fa0, 0xc000688b10})
        C:/Users/***/go/pkg/mod/grow.graphics/gd@v0.0.0-20240609070221-f7b48e68583f/internal/variant_conversions.go:200 +0x2379
grow.graphics/gd.(*instanceImplementation).Get(0xc0003b18c0, {{}, {0x7ffc354da960?, 0xc0001f5110?}})
        C:/Users/***/go/pkg/mod/grow.graphics/gd@v0.0.0-20240609070221-f7b48e68583f/register_class.go:345 +0x2f7
grow.graphics/gd/gdextension.get_func(0x4, 0xd8d9fe8a0, 0xd8d9fe750)
        C:/Users/***/go/pkg/mod/grow.graphics/gd@v0.0.0-20240609070221-f7b48e68583f/gdextension/gdextension_interface.go:2379 +0x15a
exit status 2

Example Code:

package main

import (
	"grow.graphics/gd"
	"grow.graphics/gd/gdextension"
)

type HelloWorld struct {
	gd.Class[HelloWorld, gd.Node]

	TestSignal gd.Signal[func()] `gd:"etst_signal"`
}

func main() {
	godot, ok := gdextension.Link()
	if !ok {
		panic("Unable to link to godot")
	}
	gd.Register[HelloWorld](godot)
}

Have renamed the generic gd.Signal[T] to gd.SignalAs[T], gd.Signal is now used for the underlying Godot signal value. Let me know if you continue to have any issues working with signals.

Signals work 🎉

I do have an issue with using gd.Strings as parameter on signals. Emitting results this error:

E 0:00:11:0523   emit_signalp: Error calling from signal 'twitch_follow' to callable: 'AnimationPlayer(EventPlayer.gd)::_on_godot_twitch_follow': Cannot convert argument 1 from int to String.
  <C++ Source>   core/object/object.cpp:1140 @ emit_signalp()

If I do change it to int on the GDscript side that gets called it says it cant convert Nil to int.

Setup code

type GodotTwitch struct {
  gd.Class[GodotTwitch, gd.Node]

  TwitchFollow   gd.SignalAs[func(gd.String)] `gd:"twitch_follow"`
  LatestFollower gd.String                    `gd:"latest_follower"`
}

func (h *GodotTwitch) Process(godoCtx gd.Context, delta gd.Float) {
  h.LatestFollower = h.Pin().String("A name")
  h.TwitchFollow.Emit(h.LatestFollower)
}

Cheers, have pushed a fix for this.

Hi @Splizard,

I update the gd.Signal with gd.SignalAs in the example project https://github.com/grow-graphics/eg/tree/master/2d/dodge_the_creeps
However, I got an error when I press the start button like

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x7ff98fb976d2]

The error happened around the code h.StartGame.Emit()

main.(*HUD).OnStartButtonPressed(0xc0001de000, {{0x0?, 0x0?}, 0x7ff98f98d453?})
        D:/code/godot-go/eg/2d/dodge_the_creeps/hud.go:48 +0x38

Could you help investigate?
Thanks

Same issue here.

Thanks @iuyoy and @TeddyDD for reporting this, I've fixed the issue and updated the example.