Skip to content

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 has been 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
Comment on lines 160 to 162
.unwrap_or_else(|| {
panic!("failed to resolve taffy id for child entity {child} in {entity}")
})
Copy link
Member

Choose a reason for hiding this comment

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

if I remember correctly those are not similar in how they handle formatting when not panicking

&mut out,
);

bevy_utils::tracing::info!("{out}");
Copy link
Member

Choose a reason for hiding this comment

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

tracing is already a dependency of bevy_ui

@BenjaminBrienen BenjaminBrienen added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 22, 2025
@StrikeForceZero StrikeForceZero force-pushed the dev/bevy_ui/ui_surface_update_mappings_updated branch from 4d4faaa to 2856625 Compare April 30, 2025 01:53
@StrikeForceZero
Copy link
Contributor Author

StrikeForceZero commented Apr 30, 2025

I'm not sure if GitHub failed to notify me of the label change or if I accidentally dismissed it.

I went ahead and rebased this on top of main. It looks like it overlaps with most, if not all, of the changes from #17596. I was planning to circle back to review whether any of the tests are redundant or could be cleaned up, and to update the other PRs that depend on this one.

Before going further, though, I wanted to pause and ask: is this PR still something we want to move forward with?

@BenjaminBrienen BenjaminBrienen added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Apr 30, 2025
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.

6 participants