-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Working on some comparative ECS benchmarks over at go-ecs-benchmarks, I was not able to test component random access. I.e. accessing components for a specific entity, without the use of systems or queries.
I get panic: reflect: call of reflect.Value.Type on zero Value.
Code to reproduce:
func runEnto(b *testing.B, n int) {
b.StopTimer()
world := ento.NewWorldBuilder().
WithDenseComponents(comps.Position{}).
Build(1024)
entities := make([]*ento.Entity, 0, n)
for i := 0; i < n; i++ {
e := world.AddEntity(comps.Position{})
entities = append(entities, e)
}
rand.Shuffle(n, util.Swap(entities))
b.StartTimer()
for i := 0; i < b.N; i++ {
for _, e := range entities {
var comp *comps.Position
e.Get(comp) // <--- crashes here
comp.X++
}
}
}Stack trace:
reflect.Value.typeSlow({0x0?, 0x0?, 0xc0001812e8?})
C:/Programs/Go/src/reflect/value.go:2687 +0x10e
reflect.Value.Type(...)
C:/Programs/Go/src/reflect/value.go:2682
github.com/wfranczyk/ento.(*Entity).Get(0xc000022750, {0xc000069f10?, 0xc000069ec8?, 0x1?})
C:/Users/mlange/go/pkg/mod/github.com/wfranczyk/ento@v0.1.0/entity.go:42 +0xf0
github.com/mlange-42/go-ecs-benchmarks/bench/random.runEnto(0xc0001b0008, 0x1)
C:/Data/Hack/go/arche/go-ecs-benchmarks/bench/random/ento.go:30 +0x334
github.com/mlange-42/go-ecs-benchmarks/bench/util.RunBenchmarks.func1(0xc0001b0008?)
C:/Data/Hack/go/arche/go-ecs-benchmarks/bench/util/util.go:37 +0x22
testing.(*B).runN(0xc0001b0008, 0x1)
C:/Programs/Go/src/testing/benchmark.go:193 +0xf0
testing.(*B).run1.func1()
C:/Programs/Go/src/testing/benchmark.go:215 +0x48
created by testing.(*B).run1 in goroutine 1
C:/Programs/Go/src/testing/benchmark.go:208 +0x90
Metadata
Metadata
Assignees
Labels
No labels