Skip to content

uberbuffers selects single mesh when two are added #15154

@ChristopherBiscardi

Description

@ChristopherBiscardi

Bevy version

main, 0.15.0-dev.

introduced in bc34216 by #14257

The same mesh is used even though there are two different custom meshes added. Each time the program runs, one of the two meshes is selected and used for both renders.

screenshot-2024-09-10-at-18 56 51@2x
screenshot-2024-09-10-at-18 56 38@2x

The previous commit 293e915 does not show the bug.

screenshot-2024-09-10-at-18 56 02@2x

What you did

The following program adds two different custom 2d meshes.

use bevy::{
    prelude::*,
    render::{
        mesh::PrimitiveTopology,
        render_asset::RenderAssetUsages,
    },
    sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};

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

pub fn spawn_custom_meshes(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.spawn(Camera2dBundle::default());

    let mesh_1 = Mesh::new(
        PrimitiveTopology::TriangleList,
        RenderAssetUsages::RENDER_WORLD,
    )
    .with_inserted_attribute(
        Mesh::ATTRIBUTE_POSITION,
        vec![
            [50., 0., 0.],
            [-50., 0., 0.],
            [0., 100., 0.],
            [50., 0., 0.],
        ],
    );

    commands.spawn(MaterialMesh2dBundle {
        mesh: Mesh2dHandle(meshes.add(mesh_1)),
        material: materials.add(ColorMaterial {
            color: Color::linear_rgb(0., 1., 0.),
            ..Default::default()
        }),

        transform: Transform::from_xyz(-50., 0., 0.),
        ..default()
    });

    let mesh_2 = Mesh::new(
        PrimitiveTopology::TriangleList,
        RenderAssetUsages::RENDER_WORLD,
    )
    .with_inserted_attribute(
        Mesh::ATTRIBUTE_POSITION,
        vec![
            [-50., 50., 0.],
            [50., 50., 0.],
            [0., -50., 0.],
            [-50., 50., 0.],
        ],
    );

    commands.spawn(MaterialMesh2dBundle {
        mesh: Mesh2dHandle(meshes.add(mesh_2)),
        material: materials.add(ColorMaterial {
            color: Color::linear_rgb(0., 0., 1.),
            ..Default::default()
        }),

        transform: Transform::from_xyz(50., 0., 0.),
        ..default()
    });
}

Here's a cargo.toml for ease of replication

[package]
name = "meshes"
version = "0.1.0"
edition = "2021"

[dependencies]
# main
bevy = { git = "https://github.com/bevyengine/bevy.git" }
## has bug
# bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "bc342169293187cb1e9b59bb0f6a0872f457b5d1" }
## prior commit, no bug
# bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "293e91564b20dc2971e47c79e727f7db2349024c" }

Additional information

There were some updates to the 3d pipeline to fix example regressions. Item 2 in #14375 might be relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions