grow-graphics / gd

Go + Godot 4.3
https://learn.grow.graphics/
MIT License
198 stars 9 forks source link

Iteration over gd.ArrayOf #57

Open Ullanar opened 4 weeks ago

Ullanar commented 4 weeks ago

Discussed in https://github.com/grow-graphics/gd/discussions/53

Originally posted by **Ullanar** July 29, 2024 Related to https://github.com/grow-graphics/gd/discussions/52 I simplified discussion to that func ```go func (i *InteractionManager) Process(delta float64) { lt := i.Temporary overlappingAreas := i.Area.GetOverlappingAreas(i.Temporary) for i := range overlappingAreas.Size() { fmt.Printf("name: %s", overlappingAreas.Index(lt, gd.Int(i)).AsNode().GetName(lt)) } } ``` And when areas overlapping we getting panic ``` panic: interface conversion: interface {} is gd.Object, not gd.Area2D goroutine 17 [running, locked to thread]: grow.graphics/gd/internal.TypedArray[...].Index(0x77e3317aaf80?, {{0xc000031c48?, 0xc0005115f0}, 0x77e332428e80?}, 0xc00073f890?) /home/lev/go/pkg/mod/grow.graphics/gd@v0.0.0-20240712233837-825f292a30dc/internal/arrays.go:191 +0x8a git.ywa.su/gamedev/2dp/2dp-game/modules/interaction.(*InteractionManager).Process(0x77e331576c20?, 0xc0002be580?) /home/lev/prj/ywa/gamedev/2dp/modules/interaction/interaction_manager.go:34 +0x92 grow.graphics/gd/internal/classdb.Node._process-fm.Node._process.func1({0x77e332e0afc8, 0xc0002be580}, 0x7ffe6d64a9e0, 0x9337820?) /home/lev/go/pkg/mod/grow.graphics/gd@v0.0.0-20240712233837-825f292a30dc/internal/classdb/all.go:99156 +0xa4 grow.graphics/gd.(*instanceImplementation).CallVirtual(0x77e3324089e0?, {{}, {0x77e3314018e0?, 0xc000031dc8?}}, {0x77e3314b7000?, 0xc000012108?}, 0xc000031e20?, 0x77e3306b790b?) /home/lev/go/pkg/mod/grow.graphics/gd@v0.0.0-20240712233837-825f292a30dc/register_class.go:549 +0x3f grow.graphics/gd/gdextension.call_virtual_with_data_func(0x20, 0xc2e1750, 0x23, 0x7ffe6d64a9e0, 0x0) /home/lev/go/pkg/mod/grow.graphics/gd@v0.0.0-20240712233837-825f292a30dc/gdextension/gdextension_interface.go:2560 +0x19c signal: aborted (core dumped) ``` Is that normal behavior? Also I found what if you have array with size 0 and doing `PopFront` (sure others selections too) then you also getting panic. It does not looks like safe methods :) (probably I would suggest to return also `ok` as bool)

So we defined what this is a bug. I will leave issue to track it

Splizard commented 4 weeks ago

Thanks for reporting, I'm looking to resolve this as part of the upgrade to Go 1.23 and Godot 4.3