Skip to content

19275: spawn_batch creates incorrect relationships when RelationshipTarget is initially empty #19276

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

venhelhardt
Copy link
Contributor

@venhelhardt venhelhardt commented May 18, 2025

Objective

Fixes #19275

Solution

Component hooks may observe an incoherent world state during World::spawn_batch, since commands are not flushed between entity insertions. This causing incorrect behavior when multiple entities referenced the same target entity with an initially empty RelationshipTarget - each hook would overwrite the previous.

This fix ensures that the on_insert hook operates on a consistent view when the RelationshipTarget is initially empty, by moving the logic into the command itself. It may introduce small performance overhead (about 10%) due to additional commands and lookups.

Testing

  • Did you test these changes? If so, how?: cargo test --workspace
  • Are there any parts that need more testing? I don't think so
  • How can other people (reviewers) test your changes? Is there anything specific they need to know? Test included
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test? irrelevant

…arget is initially empty

Component hooks may observe an incoherent world state during `World::spawn_batch`, since commands are not flushed between entity insertions. This causing incorrect behavior when multiple entities referenced the same target entity with an initially empty `RelationshipTarget` - each hook would overwrite the previous.

This fix ensures that the on_insert hook operates on a consistent view when the `RelationshipTarget` is initially empty, by moving the logic into the command itself.
@greeble-dev greeble-dev added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 19, 2025
Copy link
Contributor

@urben1680 urben1680 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spawn_batch creates incorrect relationships when RelationshipTarget is initially empty
3 participants