Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Do not extend layouts of inactive archetypes #416

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions ecs/archetype_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (a *archNode) CreateArchetype(layouts uint8, target Entity) *archetype {
}

func (a *archNode) ExtendArchetypeLayouts(count uint8) {
if !a.IsActive {
return
}

if !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 }

type withSlice struct {
Slice []int
Expand Down
29 changes: 29 additions & 0 deletions ecs/world_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,7 @@ func Test1000Archetypes(t *testing.T) {
_ = testStruct14{1}
_ = testStruct15{1}
_ = testStruct16{1}
_ = testStruct17{1}

w := NewWorld()

Expand Down Expand Up @@ -1878,6 +1879,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
Loading