-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
DynamicScenes contain invalid Entity references #4793
Comments
Well, I think my reflection-fu is not strong enough for this, so I'm giving up on the PR, I'll let someone with more experience in that area/more determination tackle this. |
Note that this is no longer the case since #6194. Generation is now serialized so this happens when saving and loading a scene too, making this affect a lot more use cases. Simply saving and loading a scene that contains a dynamic scene with any hierarchy now fails. |
I updated the original post to reflect this, as well as the minimal repro example 👍 |
Bevy version
Commit hash: 15acd6f (post v0.7.0)
Bug description
Minimal example
When applying
DynamicScene
s to a world using write_to_world, the operation will sometimes panic.(more specifically, it will crash if the DynamicScene was created from any entities with a generation != 0 which belong to a hierarchy)
Cause
DynamicScenes store entities without their generation, which makes sense because the simple ids are transiently unique.
However,
Entity
s stored in components (such asParent
orChildren
) still contain the generation.This means that upon applying the
DynamicScene
, the mapping phase of write_to_world will try to map the "generationful"Entity
s and will fail to find them in the map (because the map only has a 0-generation for its keys).Important note
OUTDATED
I believe most people never encounter this problem, because DynamicScenes are mainly used alongside serialization, and serialization of anEntity
strips it of its generation already. (I didn't find where in the codebase but it's what I deduce)UPDATE:
The workaround above no longer works as per #6194
Proposed fix
OUTDATED
I believe we would simply need to add a prior mapping phase in DynamicScene::from_world to strip the generation of allEntity
s contained in components.I will file a PR soon. Nevermind, I am not well-enough versed in the deep arts of reflection
UPDATE:
Since the arguments in #6194 are convincing that serializing the generation is useful, I think we need another solution.
Possibly, storing the generation in the DynamicScenes
The text was updated successfully, but these errors were encountered: