Skip allocation of zero size meshes (#19938)

# Objective

Fixes #16525
Fixes #19710

## Solution

Not allocating a mesh if it is empty.

## Testing

I tested using the following minimum repro from #16525
```rust
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.
This commit is contained in:
Connor Dalrymple 2025-07-06 21:32:51 -05:00 committed by GitHub
parent 2c6cf9a597
commit 905965b842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -452,13 +452,17 @@ impl MeshAllocator {
// Allocate.
for (mesh_id, mesh) in &extracted_meshes.extracted {
let vertex_buffer_size = mesh.get_vertex_buffer_size() as u64;
if vertex_buffer_size == 0 {
continue;
}
// Allocate vertex data. Note that we can only pack mesh vertex data
// together if the platform supports it.
let vertex_element_layout = ElementLayout::vertex(mesh_vertex_buffer_layouts, mesh);
if self.general_vertex_slabs_supported {
self.allocate(
mesh_id,
mesh.get_vertex_buffer_size() as u64,
vertex_buffer_size,
vertex_element_layout,
&mut slabs_to_grow,
mesh_allocator_settings,