Skip to content

Commit 905965b

Browse files
authored
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.
1 parent 2c6cf9a commit 905965b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/bevy_render/src/mesh/allocator.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,17 @@ impl MeshAllocator {
452452

453453
// Allocate.
454454
for (mesh_id, mesh) in &extracted_meshes.extracted {
455+
let vertex_buffer_size = mesh.get_vertex_buffer_size() as u64;
456+
if vertex_buffer_size == 0 {
457+
continue;
458+
}
455459
// Allocate vertex data. Note that we can only pack mesh vertex data
456460
// together if the platform supports it.
457461
let vertex_element_layout = ElementLayout::vertex(mesh_vertex_buffer_layouts, mesh);
458462
if self.general_vertex_slabs_supported {
459463
self.allocate(
460464
mesh_id,
461-
mesh.get_vertex_buffer_size() as u64,
465+
vertex_buffer_size,
462466
vertex_element_layout,
463467
&mut slabs_to_grow,
464468
mesh_allocator_settings,

0 commit comments

Comments
 (0)