Skip to content

Fix dynamic scene resources not being entity mapped#18395

Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom
ElliottjPierce:fix-dynamic-scene-unmapped-resources
Mar 18, 2025
Merged

Fix dynamic scene resources not being entity mapped#18395
alice-i-cecile merged 1 commit intobevyengine:mainfrom
ElliottjPierce:fix-dynamic-scene-unmapped-resources

Conversation

@ElliottjPierce
Copy link
Copy Markdown
Contributor

Objective

The resources were converted via clone_reflect_value and the cloned value was mapped. But the value that is inserted is the source of the clone, which was not mapped.

I ran into this issue while working on #18380. Having non consecutive entity allocations has caught a lot of bugs.

Solution

Use the cloned value for insertion if it exists.

Copy link
Copy Markdown
Contributor

@kristoff3r kristoff3r left a comment

Choose a reason for hiding this comment

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

Makes sense to me, but it would be nice to have a test for it

Comment on lines +152 to +156
let mut cloned_resource;
let partial_reflect_resource = if let Some(map_entities) =
registration.data::<ReflectMapEntities>()
{
cloned_resource = clone_reflect_value(resource.as_partial_reflect(), registration);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let mut cloned_resource;
let partial_reflect_resource = if let Some(map_entities) =
registration.data::<ReflectMapEntities>()
{
cloned_resource = clone_reflect_value(resource.as_partial_reflect(), registration);
let partial_reflect_resource = if let Some(map_entities) =
registration.data::<ReflectMapEntities>()
{
let mut cloned_resource = clone_reflect_value(resource.as_partial_reflect(), registration);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, cloned_resource needs to live outside the if scope. Otherwise it gets dropped at the end of the if, leaving the partial_reflect_resource with a dangling pointer. I put it outside to defeat the borrow checker lol.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah lol, fair enough

@ElliottjPierce
Copy link
Copy Markdown
Contributor Author

Makes sense to me, but it would be nice to have a test for it

Absolutely. #18380 basically makes all entity allocation/reservation order deterministic but unreliable. So it kinda makes a test for all this stuff. (I found the bug because test cases were failing).

But if #18380 or an equivalent is not merged, I'll revisit this.

@kristoff3r kristoff3r added C-Bug An unexpected or incorrect behavior A-Scenes Composing and serializing ECS objects S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Trivial Nice and easy! A great choice to get started with Bevy labels Mar 18, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 18, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 18, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Mar 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 18, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 18, 2025
Merged via the queue into bevyengine:main with commit 339914b Mar 18, 2025
38 checks passed
mockersf pushed a commit that referenced this pull request Mar 18, 2025
# Objective

The resources were converted via `clone_reflect_value` and the cloned
value was mapped. But the value that is inserted is the source of the
clone, which was not mapped.

I ran into this issue while working on #18380. Having non consecutive
entity allocations has caught a lot of bugs.

## Solution

Use the cloned value for insertion if it exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants