From 3eb96c2ec0c7f1f0415cee9a00b9e25cf3958030 Mon Sep 17 00:00:00 2001 From: Brad Beam Date: Thu, 18 Jan 2024 21:52:00 -0600 Subject: [PATCH] fix: Only draw initialized layers (#117) This fixes an issue where we'd attempt to call draw on a nil layer. Signed-off-by: Brad Beam --- ecs/ecs.go | 3 +++ ecs/ecs_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/ecs/ecs.go b/ecs/ecs.go index 3909fc7..83c28e1 100644 --- a/ecs/ecs.go +++ b/ecs/ecs.go @@ -72,6 +72,9 @@ func (ecs *ECS) DrawLayer(l LayerID, screen *ebiten.Image) { // Draw executes all draw systems. func (ecs *ECS) Draw(screen *ebiten.Image) { for _, l := range ecs.layers { + if l == nil { + continue + } l.draw(ecs, screen) } } diff --git a/ecs/ecs_test.go b/ecs/ecs_test.go index 179a9e2..c99b031 100644 --- a/ecs/ecs_test.go +++ b/ecs/ecs_test.go @@ -112,6 +112,17 @@ func TestECSLayer(t *testing.T) { } } +func TestEmptyDefaultLayer(t *testing.T) { + world := donburi.NewWorld() + ecs := NewECS(world) + + TestLayer := LayerID(1) + + ecs.AddRenderer(TestLayer, func(ecs *ECS, image *ebiten.Image) {}) + + ecs.Draw(ebiten.NewImage(1, 1)) +} + var ( testUpdatedIndex int testDrawedIndex int