Skip to content
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

DynamicScene.write_to_world panics on partial updates involving hierarchies #6702

Open
sQu1rr opened this issue Nov 20, 2022 · 1 comment
Open
Labels
A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior

Comments

@sQu1rr
Copy link
Contributor

sQu1rr commented Nov 20, 2022

Bevy version

Bevy 0.9.0

What you did

For a simple explanation, suppose I have a world entity with parent/child components. I want to update its transform component with a DynamicScene using a previously initialized EntityMap that maps the entity from the dynamic scene to the world. The dynamic scene only contains this transform component. When I do DynamicScene.write_to_world, bevy panics.

This is NOT related to issue #6573, and was also there in Bevy 0.8.1.

As a side note, the error handling seems incorrect, It unwraps/panics instead of returning Result.

What went wrong

what were you expecting?

I expect write_to_world to only update the components that are included within the DynamicScene.

I also expect that in case of an error, the function will return Result and will not panic.

what actually happened?

DynamicScene panics on write_to_world due to remapping the valid references in child/parent components.

If an entity is present in the EntityMap, its child/parent entities are remapped on every call regardless of whether the entity is present in the DynamicScene that we are inserting into the world. Basically, when the entity is already present in the world with the correct parents/children, this code tries to remap already valid values (provided that the entity mapping is present in the EntityMap).

Additional information

I am trying to do real-time network scene updates by transferring updated components only. First I transfer the whole world as a serialized dynamic scene which initializes EntityMap that I store. In later updates, I only transfer updated components and reuse the EntityMap. I use write_to_world to directly to update the world. Looking at the implementation, write_to_world was made to be able to update existing entities.

Remapping happens here:

.map_entities(world, entity_map)

For all entities in the EntityMap:

for entity in entity_map.values() {

The actual error is generated here:

*entity = entity_map.get(*entity)?;

Examples

A simplified example that breaks right away: https://pastebin.com/5qkcHnsZ
More verbose example to play with: https://pastebin.com/WRDD7rqc
Discussion on discord: https://discord.com/channels/691052431525675048/1043155921217523752/1043155921217523752

@sQu1rr sQu1rr added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 20, 2022
@Alainx277
Copy link

In my case I apply a dynamic scene to an existing entity. If the parent of that existing entity is entity 0, it will remap it thinking it comes from the dynamic scene.

The MapEntities implementations have checks trying to prevent this. For the Parent component there is a check if the parent entity matches one in the dynamic scene. The problem is: an entity 0v0 can exist in a dynamic scene (and will in most cases) and in the world at the same time (the first world entity). This makes the entity check incorrect in some circumstances.

A possible solution would be using a special entity generation for entities from dynamic scenes, ensuring that no scene entity will conflict with one already in the world.

@sQu1rr sQu1rr changed the title DynamicScene.write_to_world panics when on partial updates involving hierarchies DynamicScene.write_to_world panics when on updates involving hierarchies Nov 20, 2022
@sQu1rr sQu1rr changed the title DynamicScene.write_to_world panics when on updates involving hierarchies DynamicScene.write_to_world panics on updates involving hierarchies Nov 20, 2022
@sQu1rr sQu1rr changed the title DynamicScene.write_to_world panics on updates involving hierarchies DynamicScene.write_to_world panics on partial updates involving hierarchies Nov 20, 2022
@james7132 james7132 added A-Scenes Serialized ECS data stored on the disk and removed S-Needs-Triage This issue needs to be labelled labels Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants