Skip to content

Commit fbf486d

Browse files
authored
Prevent emitting custom events with components for the zero entity (#444)
1 parent 2d5a59d commit fbf486d

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [[v0.6.4]](https://github.com/mlange-42/ark/compare/v0.6.3...v0.6.4)
4+
5+
### Bugfixes
6+
7+
- Prevents emitting custom events with components for the zero entity (#444)
8+
39
## [[v0.6.3]](https://github.com/mlange-42/ark/compare/v0.6.2...v0.6.3)
410

511
### Other

benchmark/table/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/mlange-42/ark/benchmark"
1111
)
1212

13-
const version = "v0.6.3"
13+
const version = "v0.6.4"
1414
const goVersion = "1.25.1"
1515

1616
func main() {

ecs/events_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ func TestCustomEventErrors(t *testing.T) {
112112
world.Event(OnCreateEntity)
113113
})
114114

115+
expectPanicsWithValue(t, "can't emit event with components for the zero entity",
116+
func() {
117+
world.Event(CustomEvent).For(C[Position]()).Emit(Entity{})
118+
})
119+
115120
expectPanicsWithValue(t, "entity does not have the required event components",
116121
func() {
117122
world.Event(CustomEvent).For(C[Position]()).Emit(e)

ecs/world_internal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ func (w *World) emitEvent(e *Event, entity Entity) {
573573
func (w *World) emitEventSlowPath(e *Event, entity Entity) {
574574
var mask *bitMask
575575
if entity.IsZero() {
576+
if !e.mask.IsZero() {
577+
panic("can't emit event with components for the zero entity")
578+
}
576579
mask = &w.storage.archetypes[0].mask
577580
} else {
578581
if !w.Alive(entity) {

0 commit comments

Comments
 (0)