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

[bevy_ui/layout] Update internal mappings #16362

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

StrikeForceZero
Copy link
Contributor

@StrikeForceZero StrikeForceZero commented Nov 12, 2024

supersedes #12804

Objective

Solution

  • Updated mappings:
    • use EntityHashSet to track relationships between camera -> root nodes
    • adds tracking of camera_entity with Option<Entity> in RootNodeData (previously named RootNodePair)

Testing

  • Did you test these changes?
    Only via the existing unit/e2e tests, since rebasing the original changes from [bevy_ui/layout] UiSurface update internal mappings #12804.
  • Are there any parts that need more testing?
    Since these changes are somewhat stale, it would be worth manually confirming during runtime with various scenarios and attempts to create any undesired behavior or overlooked race conditions.
  • How can other people (reviewers) test your changes?
    • Confirm behavior improves expectations or matches existing ones on the main branch
      • Adding UI Nodes
      • Removing UI Nodes
        • Despawn
        • Despawn Recursive
        • Swap Parents
      • Changing other hierarchies and order of nodes
      • Changing various style attributes (width, height, z index, and position type), resizing windows, and translating UI nodes
      • Performance improvements or regressions?

@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 12, 2024
@alice-i-cecile alice-i-cecile added the C-Usability A targeted quality-of-life change that makes Bevy easier to use label Nov 12, 2024
.get(&child)
.cloned()
.unwrap_or_else(|| {
panic!("failed to resolve taffy id for child entity {child} in {entity}")
Copy link
Contributor Author

@StrikeForceZero StrikeForceZero Nov 12, 2024

Choose a reason for hiding this comment

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

Previously, we used a field as a scratch pad to push these IDs into, but we silently ignored the ones we failed to resolve. I was unsure if we wanted to continue silently failing or if the panic is more appropriate.

.expect("root_node_data missing");

if root_node_data.camera_entity.is_none() {
panic!("internal map out of sync");
Copy link
Contributor Author

@StrikeForceZero StrikeForceZero Nov 12, 2024

Choose a reason for hiding this comment

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

If I recall correctly, some of these panics are only possible because we expose several methods to pub(super) that could be used arbitrarily in the future and break the state. I'll need to update this one, too, but the idea with this effort is an attempt to make the state more atomic

root_node_entity: Entity,
camera_entity: Entity,
) -> &mut RootNodeData {
let user_root_node = *self.entity_to_taffy.get(&root_node_entity).expect("create_or_update_root_node_data called before root_node_entity was added to taffy tree or was previously removed");
Copy link
Contributor Author

@StrikeForceZero StrikeForceZero Nov 12, 2024

Choose a reason for hiding this comment

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

This feels weird coming back to, but if memory is serving today, it's related to the non-atomic nature of how the layout module (super) could call these methods.. Theoretically, the node should be upserted when added well before we call set_camera_children.

(also note how set_camera_children is pub, not pub(super)...)

@BenjaminBrienen BenjaminBrienen added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants