Skip to content

Preserve entity identities across World.TrimExcess - #316

Closed
snowyukitty wants to merge 1 commit into
genaray:masterfrom
snowyukitty:fix/trim-excess-entity-ids
Closed

snowyukitty wants to merge 1 commit into
genaray:masterfrom
snowyukitty:fix/trim-excess-entity-ids

Conversation

@snowyukitty

Copy link
Copy Markdown

Fixes #315.

TrimExcess() currently drops recycled IDs above the reduced chunk capacity. Once the remaining queue is exhausted, entity creation falls back to Size, which can reuse the ID and version of a surviving entity. Trimming an empty world also loses the versions needed to keep destroyed handles invalid.

Preserve the recycled ID/version queue with Queue.TrimExcess() instead of filtering its contents. The shared allocator restores entity metadata capacity when an ID is outside the trimmed array, so both single and batch creation can safely reuse high IDs without retaining all metadata after a trim. Chunk storage still shrinks, while recycled IDs retain the generations required for safe reuse.

Regression tests cover surviving entities and their component values, high recycled IDs over repeated trim/reuse cycles, and destroyed handles after empty-world trimming. Each scenario exercises single and batch creation. The existing trimming test also checks that reusing its first high ID stays in bounds.

Validation: built all library target frameworks and ran the complete NUnit suite for Debug, Debug-Events, Debug-PureECS, Release, Release-Events, and Release-PureECS. All six new regression cases fail on the unmodified upstream base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: World.TrimExcess drops recycled ids, new entities then reuse the id of a live entity

1 participant