Skip to content

Conversation

@beicause
Copy link
Contributor

@beicause beicause commented Dec 18, 2025

Objective

When using Indices::U16 (or custom vertex attributes that have padding elements), the MeshAllocator::mesh_index_slice doesn't take padding elems into account.
For example, run the lines example with the following change:

diff --git a/examples/3d/lines.rs b/examples/3d/lines.rs
index c29e9fb45..c9fcff054 100644
--- a/examples/3d/lines.rs
+++ b/examples/3d/lines.rs
@@ -121,6 +121,13 @@ impl From<LineStrip> for Mesh {
             PrimitiveTopology::LineStrip,
             RenderAssetUsages::RENDER_WORLD,
         )
+        .with_inserted_indices(bevy::mesh::Indices::U16(
+            line.points
+                .iter()
+                .enumerate()
+                .map(|(i, _v)| i as u16)
+                .collect(),
+        ))
         // Add the point positions as an attribute
         .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, line.points)
     }

The index count of LineStrip should be 3 with 1 padding in the slab, which should be 3 vertexes but RenderDoc shows 4 vertexes:
屏幕截图_20251218_192125
屏幕截图_20251218_191554

Solution

Fix MeshAllocator by taking padding elements into account and subtract it from the end of the range.

Testing

Run lines example with above patch, the index count is correct:
屏幕截图_20251218_191455

@beicause beicause changed the title MeshAllocator: Account for padded elements in the MeshBufferSlice's range MeshAllocator: Account for padding elements in the MeshBufferSlice's range Dec 18, 2025
@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 Dec 18, 2025
@beicause beicause changed the title MeshAllocator: Account for padding elements in the MeshBufferSlice's range MeshAllocator: Take padding elements into account in the MeshBufferSlice's range Dec 20, 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 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.

2 participants