From 216fedc77b22c51beed5c4817b9bb1237f5cc1e4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 8 Nov 2024 19:45:46 +0100 Subject: [PATCH] Fix crash, if no triangles are being rendered --- experiments/2024-10-30/src/render.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/experiments/2024-10-30/src/render.rs b/experiments/2024-10-30/src/render.rs index 1ad9eec7c..dd80e0f17 100644 --- a/experiments/2024-10-30/src/render.rs +++ b/experiments/2024-10-30/src/render.rs @@ -264,18 +264,20 @@ impl Renderer { occlusion_query_set: None, }); - render_pass.set_index_buffer( - index_buffer.slice(..), - wgpu::IndexFormat::Uint32, - ); - render_pass.set_vertex_buffer(0, vertex_buffer.slice(..)); - render_pass.set_pipeline(&self.pipeline); - render_pass.set_bind_group(0, &self.bind_group, &[]); - render_pass.draw_indexed( - 0..mesh_triangles.len() as u32 * 3, - 0, - 0..1, - ); + if !indices.is_empty() || !vertices.is_empty() { + render_pass.set_index_buffer( + index_buffer.slice(..), + wgpu::IndexFormat::Uint32, + ); + render_pass.set_vertex_buffer(0, vertex_buffer.slice(..)); + render_pass.set_pipeline(&self.pipeline); + render_pass.set_bind_group(0, &self.bind_group, &[]); + render_pass.draw_indexed( + 0..mesh_triangles.len() as u32 * 3, + 0, + 0..1, + ); + } } self.queue.submit(Some(encoder.finish()));