Skip to content

Skip allocation of zero size meshes #19938

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kerstop
Copy link

@kerstop kerstop commented Jul 3, 2025

Objective

Fixes #16525
Fixes #19710

Solution

Not allocating a mesh if it is empty.

Testing

I tested using the following minimum repro from #16525

use bevy::{asset::RenderAssetUsages, prelude::*, render::mesh::PrimitiveTopology};

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

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    commands.spawn(Camera2d);

    let mesh = Mesh::new(
        PrimitiveTopology::TriangleList,
        RenderAssetUsages::default(),
    );

    commands.spawn((
        Mesh2d(meshes.add(mesh)),
        MeshMaterial2d(materials.add(Color::hsl(180.0, 0.95, 0.7))),
    ));
}

I was able to test on webgl2 and windows native and the issue seems to be resolved. I am not familiar with how mesh rendering works and feel like just skipping meshes should cause issues but I did not notice any.

Copy link
Contributor

github-actions bot commented Jul 3, 2025

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 3, 2025
@alice-i-cecile alice-i-cecile requested a review from atlv24 July 3, 2025 19:40
@alice-i-cecile alice-i-cecile added the O-WebGL2 Specific to the WebGL2 render API label Jul 3, 2025
@alice-i-cecile alice-i-cecile requested a review from rparrett July 3, 2025 19:41
@alice-i-cecile alice-i-cecile added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-WebGL2 Specific to the WebGL2 render API S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Creating a mesh with no attributes panics with an undescriptive error webgl2: Mesh without triangles panics
2 participants