bevyengine/bevy · error

The inner and outer meshes should have the same number of ve

Error message

The inner and outer meshes should have the same number of vertices, and have required attributes

What it means

Panic in RingMeshBuilder::build (crates/bevy_mesh/src/primitives/dim2.rs:1453). A Ring<P> is meshed by reading POSITION, NORMAL and UV_0 from both its inner and outer shape instances; the else-branch panics when get_vertex_attributes() returns None (an attribute is missing on either instance) or when the inner and outer vertex counts differ, because the ring's index stitching assumes matching loops.

Source

Thrown at crates/bevy_mesh/src/primitives/dim2.rs:1453

            {
                *b = 0;
                *e = 0;
                *f = points;
            }

            let mut positions = outer_positions;
            positions.extend_from_slice(&inner_positions);

            Mesh::new(
                PrimitiveTopology::TriangleList,
                RenderAssetUsages::default(),
            )
            .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions)
            .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
            .with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs)
            .with_inserted_indices(Indices::U32(indices))
        } else {
            panic!("The inner and outer meshes should have the same number of vertices, and have required attributes");
        }
    }
}

impl<P> Extrudable for RingMeshBuilder<P>
where
    P: Primitive2d + Meshable,
    P::Output: Extrudable,
{
    /// A list of the indices each representing a part of the perimeter of the mesh.
    ///
    /// # Panics
    ///
    /// Panics if the following assumptions are not met.
    ///
    /// It is assumed that the inner and outer meshes have the same number of vertices.
    /// If not, then the [`MeshBuilder`] of the underlying 2d primitive has generated
    /// a different number of vertices for the inner and outer instances of the primitive.

View on GitHub (pinned to 396ca72708)

Solutions

  1. Make your custom builder emit the exact same number of vertices regardless of the instance's scale/parameters
  2. Ensure the built mesh always inserts Mesh::ATTRIBUTE_POSITION, Mesh::ATTRIBUTE_NORMAL and Mesh::ATTRIBUTE_UV_0
  3. Unit-test your Primitive2d inside Ring::new(...).mesh().build() so regressions panic in CI, not at runtime

Example fix

// before: vertex count depends on the shape's radius -> inner/outer mismatch
impl Meshable for MyShape {
    fn build(&self) -> MeshBuilder {
        let n = (self.radius * 32.0) as usize; // inner ring gets fewer vertices
        MeshBuilder::new(&self.primitive, n)
    }
}
Ring::new(MyShape::default(), 2.0, 32).mesh().build(); // panic at dim2.rs:1453

// after: fixed resolution independent of scale
impl Meshable for MyShape {
    fn build(&self) -> MeshBuilder {
        MeshBuilder::new(&self.primitive, 32)
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// For custom Primitive2d used inside Ring<P>: verify the contract before building
fn ring_safe(primitive: &MyShape) -> bool {
    let a = primitive.build().build();       // outer instance
    let b = primitive.scaled(0.5).build().build(); // inner instance
    let attr = |m: &Mesh| (m.attribute(Mesh::ATTRIBUTE_POSITION).is_some()
        && m.attribute(Mesh::ATTRIBUTE_NORMAL).is_some()
        && m.attribute(Mesh::ATTRIBUTE_UV_0).is_some());
    attr(&a) && attr(&b)
        && a.count_vertices() == b.count_vertices()
}

Prevention

When it happens

Trigger: Calling .mesh().build() on a Ring<P> built around a custom Primitive2d whose Meshable implementation produces different vertex counts for the scaled inner instance vs the outer instance, or omits ATTRIBUTE_POSITION/ATTRIBUTE_NORMAL/ATTRIBUTE_UV_0. Built-in primitives satisfy the contract, so this is effectively a custom-builder contract violation.

Common situations: Implementing Meshable/Extrudable for your own 2D shape and wrapping it in Ring; a resolution parameter that affects vertex count non-uniformly when the shape is scaled; refactoring a custom builder and dropping an attribute insert.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/f6f5ca113d378510. Report an issue: GitHub.