Fix dynamic scene resources not being entity mapped#18395
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Mar 18, 2025
Merged
Conversation
kristoff3r
approved these changes
Mar 18, 2025
Contributor
kristoff3r
left a comment
There was a problem hiding this comment.
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); |
Contributor
There was a problem hiding this comment.
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); |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
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. |
alice-i-cecile
approved these changes
Mar 18, 2025
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.
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.
Objective
The resources were converted via
clone_reflect_valueand 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.