ecs: setCapacity in the ECS doesn't adjust component arrays to reflect their new location within ArchetypeStorage #341

Closed
opened 2022-06-11 13:21:32 +00:00 by tauoverpi · 0 comments
tauoverpi commented 2022-06-11 13:21:32 +00:00 (Migrated from github.com)

github.com/hexops/mach@1c0930b404/ecs/src/entities.zig (L152-L155)

This implementation of setCapacity assumes that component arrays have the same position after expanding capacity which ends up with them overwriting one another after expanding archetype storage as the position of each array is shifted forward by new_capacity - storage.capacity * size_of_previous_component.

Thus is should instead be closer to:

As far as I understand this implementation of it.

layout

In short, setCapacity doesn't perform step 3 thus leaving arrays overlapping in memory.

https://github.com/hexops/mach/blob/1c0930b40464b9abc46de429609f58e2097d751f/ecs/src/entities.zig#L152-L155 This implementation of `setCapacity` assumes that component arrays have the same position after expanding capacity which ends up with them overwriting one another after expanding archetype storage as the position of each array is shifted forward by `new_capacity - storage.capacity * size_of_previous_component`. Thus is should instead be closer to: - https://gist.github.com/tauoverpi/6f4832a406e49ad112a88395fa787374#file-aecs-zig-L335 - https://gist.github.com/tauoverpi/6f4832a406e49ad112a88395fa787374#file-aecs-zig-L396 As far as I understand this implementation of it. ![layout](https://user-images.githubusercontent.com/45411401/173189709-8e2e44e4-c07f-4469-a1e0-a0ebcc76eb98.png) In short, `setCapacity` doesn't perform step 3 thus leaving arrays overlapping in memory.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#341
No description provided.