bevyengine/bevy · error · MeshTrianglesError
Source mesh does not have primitive topology TriangleList or
Error message
Source mesh does not have primitive topology TriangleList or TriangleStrip
What it means
Mesh::triangles() (crates/bevy_mesh/src/mesh.rs:2540) can only produce Triangle3d faces from meshes whose primitive_topology is TriangleList or TriangleStrip. Any other topology (PointList, LineList, LineStrip) reaches the fallback arm and returns MeshTrianglesError::WrongTopology.
Source
Thrown at crates/bevy_mesh/src/index.rs:68
#[derive(Debug, Error)]
pub enum MeshWindingInvertError {
/// This error occurs when you try to invert the winding for a mesh with [`PrimitiveTopology::PointList`](super::PrimitiveTopology::PointList).
#[error("Mesh winding inversion does not work for primitive topology `PointList`")]
WrongTopology,
/// This error occurs when you try to invert the winding for a mesh with
/// * [`PrimitiveTopology::TriangleList`](super::PrimitiveTopology::TriangleList), but the indices are not in chunks of 3.
/// * [`PrimitiveTopology::LineList`](super::PrimitiveTopology::LineList), but the indices are not in chunks of 2.
#[error("Indices weren't in chunks according to topology")]
AbruptIndicesEnd,
#[error("Mesh access error: {0}")]
MeshAccessError(#[from] MeshAccessError),
}
/// An error that occurred while trying to extract a collection of triangles from a [`Mesh`](super::Mesh).
#[derive(Debug, Error)]
pub enum MeshTrianglesError {
#[error("Source mesh does not have primitive topology TriangleList or TriangleStrip")]
WrongTopology,
#[error("Source mesh position data is not Float32x3")]
PositionsFormat,
#[error("Face index data references vertices that do not exist")]
BadIndices,
#[error("mesh access error: {0}")]
MeshAccessError(#[from] MeshAccessError),
}
/// An array of indices into the [`VertexAttributeValues`](super::VertexAttributeValues) for a mesh.
///
/// It describes the order in which the vertex attributes should be joined into faces.
#[derive(Debug, Clone, Reflect, PartialEq)]
#[reflect(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub enum Indices {View on GitHub (pinned to 396ca72708)
Solutions
- Check mesh.primitive_topology() is TriangleList or TriangleStrip before calling triangles()
- Skip non-triangle meshes in generic iteration code
- Rebuild the mesh with a triangle topology if triangle data was actually expected
Example fix
// before
let tris: Vec<Triangle3d> = mesh.triangles()?.collect(); // Err(WrongTopology) on lines/points
// after
let tris = if matches!(
mesh.primitive_topology(),
PrimitiveTopology::TriangleList | PrimitiveTopology::TriangleStrip
) {
mesh.triangles()?.collect::<Vec<_>>()
} else {
Vec::new()
}; Defensive patterns
Strategy: validation
Validate before calling
fn has_triangle_topology(mesh: &Mesh) -> bool {
matches!(
mesh.primitive_topology(),
PrimitiveTopology::TriangleList | PrimitiveTopology::TriangleStrip
)
}
if has_triangle_topology(&mesh) {
let tris: Vec<_> = mesh.triangles()?.collect();
} Try / catch
match mesh.triangles() {
Ok(iter) => { /* iterate Triangle3d faces */ }
Err(MeshTrianglesError::WrongTopology) => { /* skip non-triangle meshes */ }
Err(other) => { /* positions/access errors */ }
} Prevention
- Filter meshes by topology before triangle-based physics/picking passes
- Document the topology each asset loader produces
- Use type-state or wrapper types to separate triangle meshes from line/point meshes
When it happens
Trigger: mesh.triangles() or mesh.triangles_mut() on a mesh whose primitive_topology() is PointList, LineList or LineStrip.
Common situations: Physics or raytracing code that iterates triangles of every mesh, including particle or line meshes; UI/debug pipelines fed with non-triangle meshes; imported assets whose topology differs from the loader expectation.
Related errors
- Mesh winding inversion does not work for primitive topology
- Source mesh position data is not Float32x3
- Face index data references vertices that do not exist
- mesh access error: {0}
- cannot convert VertexAttributeValues::{variant} to {into}
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/cdfb40bcf6260ccc.
Report an issue: GitHub.