-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Bevy version
0.11.1
What you did
I'm writing a UI system that has a "virtual DOM" similar to what React does. This entails doing a "diff" between the old and new node hierarchy, and then incrementally patching the tree of entities based on what's changed.
What I have discovered is that Bevy UI doesn't like this very much. Specifically, when I have a node that has some number of children, and I replace some of the children but not others, the layout gets messed up. Even more significant, is that if I resize the window even a tiny bit, the layout fixes itself. So something is not getting refreshed.
Specifically, what I am doing is (pseudo-code):
- For a given entity
- visit each child to see if that child changed.
- If the child changed, replace it with a new child entity and despawn the old one and its descendants.
- If the child did not change, keep it
- Now take the vector of all the new child ids - both the ones that were kept from before, and the ones that are new - and call
parent.replace_children(). - Finally, recurse downward and do the same for each child element.
- visit each child to see if that child changed.
What went wrong
What I'm seeing is that the node layout is random, nodes appearing displaced from where they should be, nodes off the edge of the screen and so on.
Additional information
The problem only seems to manifest when I enable mixing of new and old children. I can disable the bug in one of two ways: either by re-creating the node tree every time (by disabling the diff algorithm), or by not mutating the tree at all.
I realize that you'll probably want a reproducible case. I can provide this, but it's a considerable amount of work and will take some time. That is, I can easily demonstrate the bug in my current github repo, but if you want a "minimal" example I'll need to spend time cutting out all of the parts of the game that aren't relevant to the bug, which can go on a branch or something.
Let me know what you need.