Skip to content

Commit

Permalink
Fix: Do not extend layouts of inactive archetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 committed Apr 28, 2024
1 parent 1f3a735 commit 6bb53b0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [[unpublished]](https://github.com/mlange-42/arche/compare/v0.11.0...main)
## [[v0.12.0]](https://github.com/mlange-42/arche/compare/v0.11.0...v0.12.0)

### Features

Expand All @@ -12,6 +12,10 @@

* Re-arrange struct fields to save memory in a few places (#413)

### Bugfixes

* Fix crash caused by extending layouts of an inactive archetype (#416, reported in #415)

### First-time contributors

* [delaneyj](https://github.com/delaneyj)
Expand Down
2 changes: 1 addition & 1 deletion ecs/archetype_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (a *archNode) CreateArchetype(layouts uint8, target Entity) *archetype {
}

func (a *archNode) ExtendArchetypeLayouts(count uint8) {
if !a.HasRelation {
if a.IsActive && !a.HasRelation {
a.archetype.ExtendLayouts(count)
return
}
Expand Down
1 change: 1 addition & 0 deletions ecs/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type testStruct13 struct{ val int32 }
type testStruct14 struct{ val int32 }
type testStruct15 struct{ val int32 }
type testStruct16 struct{ val int32 }
type testStruct17 struct{ val int32 }

Check failure on line 63 in ecs/types_test.go

View workflow job for this annotation

GitHub Actions / Run linters

field val is unused (U1000)

type withSlice struct {
Slice []int
Expand Down
28 changes: 28 additions & 0 deletions ecs/world_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,34 @@ func TestWorldExtendLayouts(t *testing.T) {
}
}

func TestWorldExtendLayouts2(t *testing.T) {
w := NewWorld()

id1 := ComponentID[testStruct0](&w)
id2 := ComponentID[testStruct1](&w)
_ = ComponentID[testStruct2](&w)
_ = ComponentID[testStruct3](&w)
_ = ComponentID[testStruct4](&w)
_ = ComponentID[testStruct5](&w)
_ = ComponentID[testStruct6](&w)
_ = ComponentID[testStruct7](&w)
_ = ComponentID[testStruct8](&w)
_ = ComponentID[testStruct9](&w)
_ = ComponentID[testStruct10](&w)
_ = ComponentID[testStruct11](&w)
_ = ComponentID[testStruct12](&w)
_ = ComponentID[testStruct13](&w)
_ = ComponentID[testStruct14](&w)

_ = w.NewEntity(id1, id2)

_ = ComponentID[testStruct15](&w)
_ = ComponentID[testStruct16](&w)
id17 := ComponentID[testStruct17](&w)

_ = w.NewEntity(id17)
}

func TestWorldPointerStressTest(t *testing.T) {
w := NewWorld()

Expand Down

0 comments on commit 6bb53b0

Please sign in to comment.