Skip to content

Commit

Permalink
fix: Only draw initialized layers (#117)
Browse files Browse the repository at this point in the history
This fixes an issue where we'd attempt to call draw on a nil layer.

Signed-off-by: Brad Beam <brad.beam@b-rad.info>
  • Loading branch information
bradbeam committed Jan 19, 2024
1 parent 74ec566 commit 3eb96c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
11 changes: 11 additions & 0 deletions ecs/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3eb96c2

Please sign in to comment.