ShadowApex / godot-go

Go language bindings for the Godot Engine's GDNative API.
MIT License
363 stars 31 forks source link

Probelm with AnimationPlayer (suspecting gd.Real does not translate well) #47

Open mastern2k3 opened 5 years ago

mastern2k3 commented 5 years ago

Description

I started using godot-go recently and I gotta say - the work you've done here is amazing and I'd love to contribute and make it more stable - that saying, I have a problem I can't figure how to solve.

The bindings work fine but for some reason, the AnimationPlayer element is behaving odd. Calling .Play() or .GetCurrentAnimationLength() seem to behave as if the gd.Real parameters and return values map to 0.

Things I've tried doing with no success:

I've created an example project repo for convenience: https://github.com/mastern2k3/godot-go-animtest

Would love help on this or maybe a new thread to follow, thanks in advance!

Details

Go version go version go1.11 linux/amd64
Godot version 3.1.stable.official
Godot-Go version/commit hash master branch "1746202"
OS Linux Mint 19.1 linux/amd64
mastern2k3 commented 5 years ago

I discovered that if you use the generic .Get func(property String) Variant and .Callv func(method String, argArray Array) Variant you get the normal behavior, e.g.:

// len := anim.GetCurrentAnimationLength()
len := anim.Get("current_animation_length")

@ShadowApex can you maybe make sense of this?

pcting commented 4 years ago

i ran into the same issue. i'm going to see if i can get to the bottom of this. looks like it might be a mangling of arguments

pcting commented 3 years ago

just an update. the fix is to cast float arguments into C.double when constructing the argument array when calling ptrcall. This needs to be done for all floating point arguments regardless if the argument is documented as just single precision C.float. Because this project seems to be abandoned, I've implemented the fix in my implementation of godot-go here https://github.com/godot-go/godot-go

you can see an example of the use of the function here: https://github.com/godot-go/godot-go/blob/master/test/pkg/gdnativetest/object_player_character.go#L161

you can look at the code generation here: https://github.com/godot-go/godot-go/blob/master/pkg/gdnative/classes.gen.go. You'll have to search for func (o AnimationPlayerImpl) Play to find the implementation.

mastern2k3 commented 3 years ago

@pcting Nice Job! Was trying to figure this out myself to produce a fix but failed. What was your investigation process? how did you understand this?

pcting commented 3 years ago

my best reference was looking at the godot-cpp project. it also helped asking questions in the gdnative-dev room on the discord servers. i originally decided to create my own godot-go library to better understand cgo, gdnative, and nativescript.

it's a very difficult process as the only real tool to debug cgo is gdb as lldb gets confused when stepping through the go code. i could probably write a medium article on the hurdles and hardships i went through to get the project where it's at.

mastern2k3 commented 3 years ago

Would love to help you maintain a new godot-go repo. My experience with cgo is pretty weak and I would love to learn how to use gdb and lldb in this context. I already have some fix enabling compilation to arm on a fork, I'll adjust it and PR https://github.com/godot-go/godot-go.