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

UI extraction functions have nondeterministic ordering #9097

Closed
ickshonpe opened this issue Jul 10, 2023 · 0 comments · Fixed by #9099
Closed

UI extraction functions have nondeterministic ordering #9097

ickshonpe opened this issue Jul 10, 2023 · 0 comments · Fixed by #9099
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@ickshonpe
Copy link
Contributor

Bevy version

0.11

What you did

use bevy::prelude::*;

fn main() {
    App::new()
    .add_plugins(DefaultPlugins)
    .add_systems(Startup, setup)
    .run()
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
    commands.spawn(Camera2dBundle::default());
    let image = asset_server.load("numbered_grid_texture_atlas.png");
    let texture_atlas = TextureAtlas::from_grid(image.clone(), 16. * Vec2::ONE, 4, 4, None, None);
    let texture_atlas_handle = texture_atlases.add(texture_atlas);
    commands.spawn(NodeBundle {
        style: Style {
            padding: UiRect::all(Val::Px(10.)),
            column_gap: Val::Px(10.),
            ..Default::default()
        },
        ..Default::default()
    }).with_children(|commands| {
        commands.spawn((NodeBundle {
            style: Style {
                width: Val::Px(400.),
                height: Val::Px(400.),
                border: UiRect::all(Val::Px(10.)),
                ..Default::default()
            },
            border_color: BorderColor(Color::RED),
            background_color: Color::WHITE.into(),
            ..Default::default()
        },
            texture_atlas_handle.clone(),
            UiTextureAtlasImage { index: 1, ..Default::default() },
        ));    
        commands.spawn((NodeBundle {
            style: Style {
                width: Val::Px(400.),
                height: Val::Px(400.),
                border: UiRect::all(Val::Px(10.)),
                ..Default::default()
            },
            border_color: BorderColor(Color::RED),
            background_color: Color::WHITE.with_a(0.5).into(),
            ..Default::default()
        },
            texture_atlas_handle,
            UiTextureAtlasImage { index: 1, ..Default::default() },
        ));    
    });
}

What went wrong

Run the example once, borders drawn before texture atlas image nodes:
borders_order_bug

Run it again, borders drawn after:
border_order_bug_2

In bevy_ui::render::build_ui_render:

        .add_systems(
            ExtractSchedule,
            (
                extract_default_ui_camera_view::<Camera2d>,
                extract_default_ui_camera_view::<Camera3d>,
                extract_uinodes.in_set(RenderUiSystem::ExtractNode),
                extract_atlas_uinodes.after(RenderUiSystem::ExtractNode),
                extract_uinode_borders.after(RenderUiSystem::ExtractNode),
                #[cfg(feature = "bevy_text")]
                extract_text_uinodes.after(RenderUiSystem::ExtractNode),
            ),
        )

extract_uinode_borders and extract_text_uinodes both need to run after extract_atlas_uinodes.

Additional details

The order for extract_text_uinodes and extract_uinode_borders doesn't matter because the borders query has a Without<ContentSize> filter which means that text nodes can't have borders. It wasn't clear how borders for intrinsically sized nodes should be implemented, so the filter was added to sidestep the issue. But extract_atlas_uinodes was added after the borders PR and this issue with the system ordering was missed.

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jul 10, 2023
@Selene-Amanita Selene-Amanita added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jul 10, 2023
github-merge-queue bot pushed a commit that referenced this issue Jul 23, 2023
# Objective

Fixes #9097

## Solution

Reorder the `ExtractSchedule` so that the `extract_text_uinodes` and
`extract_uinode_borders` systems are run after `extract_atlas_uinodes`.

## Changelog

`bevy_ui::render`:
* Added the `ExtractAtlasNode` variant to `RenderUiSystem`.
* Changed `ExtractSchedule` so that `extract_uinode_borders` and
`extract_text_uinodes` run after `extract_atlas_uinodes`.
cart pushed a commit that referenced this issue Aug 10, 2023
# Objective

Fixes #9097

## Solution

Reorder the `ExtractSchedule` so that the `extract_text_uinodes` and
`extract_uinode_borders` systems are run after `extract_atlas_uinodes`.

## Changelog

`bevy_ui::render`:
* Added the `ExtractAtlasNode` variant to `RenderUiSystem`.
* Changed `ExtractSchedule` so that `extract_uinode_borders` and
`extract_text_uinodes` run after `extract_atlas_uinodes`.
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-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants