gd
gd copied to clipboard
Access to custom Resource's property crash the game
Thanks for quickly fix for gd.ArrayOf. By using it I'm able to create custom resource for asset list. But when trying to load them in runtime, they don't looks like they are in correct form. When trying to access to the scene list in the resource, it crashes. MRP attached, you can use gd run to reproduce it.
the code,
package main
import (
"fmt"
"grow.graphics/gd"
"grow.graphics/gd/gdextension"
)
// Testlib
//
type TestLib struct {
gd.Class[TestLib, gd.Resource] `gd:"TestLib"`
Prefabs gd.ArrayOf[gd.PackedScene]
Number gd.Int
}
var TestLibInstance *TestLib
func InitLib(ctx gd.Context) {
lib, succeed := gd.Load[TestLib](ctx, "res://TestLib.tres")
if !succeed {
fmt.Println("Error: Can't load res://TestLib.tres.")
return
}
fmt.Print("Lib ", lib)
fmt.Print("Prefab Count ", lib.Prefabs.Size()) // CRASH
TestLibInstance = &lib
for i := 0; i < int(TestLibInstance.Prefabs.Size()); i++ {
fmt.Println("element ", TestLibInstance.Prefabs.Index(ctx, int64(i)).Super().GetName(ctx))
}
}
func (l TestLib) AsResource() gd.Resource { return *l.Super() }
// Booter
//
type Booter struct {
gd.Class[Booter, gd.Node3D] `gd:"Booter"`
}
func (mc *Booter) Ready(ctx gd.Context) {
fmt.Println("Boot up")
InitLib(ctx)
}
// Main
func main() {
godot, ok := gdextension.Link()
if !ok {
panic("could not link to godot")
}
gd.Register[TestLib](godot)
gd.Register[Booter](godot)
}
output log
D:\Workspace2\testGrow\customResource>gd run
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org
Vulkan API 1.3.224 - Forward+ - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 2060
Boot up
Lib {{{[] {[] {[] {0 0xc000604680}}}}} <nil> 0}exit status 0xc0000005