grow-graphics/gd

Iteration over gd.ArrayOf

Closed this issue · 3 comments

Discussed in #53

Originally posted by Ullanar July 29, 2024
Related to #52

I simplified discussion to that func

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

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

Should be fixed now, you should be able to do this:

func (i *InteractionManager) Process(delta float64) {
	lt := i.Temporary

	overlappingAreas := i.Area.GetOverlappingAreas(i.Temporary)

	for _, area := range overlappingAreas.Iter() {
		fmt.Printf("name: %s", area.AsNode().GetName(lt))
	}
}

That`s great, will check it soon!