Repository navigation
Conversation
world_delete walked idr.records with next() while the recursive world_delete could create archetypes that still contain the deleted id (deleting a dependent strips (R, child) from another entity that also has the id). archetype_create then inserted new keys into the records being traversed, which is undefined for next(), and the archetypes that landed behind the iterator were never visited: their entities survived the delete, kept the dead id, and still matched queries. Iterate a snapshot of the archetype ids and take a new snapshot until a pass deletes nothing. Each repeated pass deletes at least one entity, so the loop terminates.
The (R, *) branch of world_delete had the same problem as the one fixed for #322: it walked idr_r.records with next() while the recursive world_delete could create archetypes with (R, *) pairs (deleting a dependent strips (S, child) from another entity that also has (R, t)), inserting keys into the records mid-traversal. Entities in archetypes that landed behind the iterator survived world:delete(R). Use the same snapshot-and-repeat loop as the component branch.
Owner
|
AI-generated pull requests will be closed. There is a lot of ai-prose in both the code and in this message. Repeat submissions may result in a ban. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Description of your Changes.
Fixes #322.
In
world_delete, the(OnDelete, Delete)branch iteratesidr.recordswithnext(), and each recursiveworld_deletecan create new archetypes (archetype_traverse_remove->archetype_create->archetype_append_to_records), which inserts new keys into that same table mid-traversal. Assigning to a non-existent key duringnext()traversal is undefined, and in practice some archetypes get skipped. Entities in them survive the delete, keep the deleted component, and still matchquery(e). With the repro from the issue, 13 of 50 survive.The loop now snapshots the archetype ids, deletes from each (skipping any already destroyed by a recursive call), and repeats until a pass deletes nothing. A pass only repeats if it deleted something, and the cascade never creates entities, so it terminates.
The second commit applies the same change to the
(R, *)relation branch (idr_r.records), which has the same pattern (17/31/50 survivors for 64/100/200 targets before).None of the repros use hooks, so this isn't the on_remove structural-change case from #324.
Impact of your Changes
(OnDelete, Delete)now deletes every entity with the id, as documented inhow_to/100_cleanup_traits.luau. Plain deletes and Remove policies are untouched.Perf (median of interleaved runs, 21 reps): plain delete of 65536 entities, large tag/relation cascades and ChildOf cascades are within noise. Many tiny
(OnDelete, Delete)cascades cost about 1-3% more, from one snapshot table per call.Tests Performed
New cases in
TEST("world:delete()"), asserting world state (contains,query,component_index):(OnDelete, Delete)cascades with a surviving bystander(R, *)case, 5 layouts(OnDelete, Remove),(OnDeleteTarget, Delete)across 64 archetypes, deleting an id with no dependentsluau test/tests.luau: 153/153 on the branch; the 3 cascade tests fail on current main.Additional Comments
The repros from #326 and #327 give the expected result on current main; they look fixed by #340.