{"record":{"id":"cdfb40bcf6260ccc","repo":"bevyengine/bevy","slug":"source-mesh-does-not-have-primitive-topology-trian","errorCode":null,"errorMessage":"Source mesh does not have primitive topology TriangleList or TriangleStrip","messagePattern":"Source mesh does not have primitive topology TriangleList or TriangleStrip","errorType":"exception","errorClass":"MeshTrianglesError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/index.rs","lineNumber":68,"sourceCode":"#[derive(Debug, Error)]\npub enum MeshWindingInvertError {\n    /// This error occurs when you try to invert the winding for a mesh with [`PrimitiveTopology::PointList`](super::PrimitiveTopology::PointList).\n    #[error(\"Mesh winding inversion does not work for primitive topology `PointList`\")]\n    WrongTopology,\n\n    /// This error occurs when you try to invert the winding for a mesh with\n    /// * [`PrimitiveTopology::TriangleList`](super::PrimitiveTopology::TriangleList), but the indices are not in chunks of 3.\n    /// * [`PrimitiveTopology::LineList`](super::PrimitiveTopology::LineList), but the indices are not in chunks of 2.\n    #[error(\"Indices weren't in chunks according to topology\")]\n    AbruptIndicesEnd,\n    #[error(\"Mesh access error: {0}\")]\n    MeshAccessError(#[from] MeshAccessError),\n}\n\n/// An error that occurred while trying to extract a collection of triangles from a [`Mesh`](super::Mesh).\n#[derive(Debug, Error)]\npub enum MeshTrianglesError {\n    #[error(\"Source mesh does not have primitive topology TriangleList or TriangleStrip\")]\n    WrongTopology,\n\n    #[error(\"Source mesh position data is not Float32x3\")]\n    PositionsFormat,\n\n    #[error(\"Face index data references vertices that do not exist\")]\n    BadIndices,\n    #[error(\"mesh access error: {0}\")]\n    MeshAccessError(#[from] MeshAccessError),\n}\n\n/// An array of indices into the [`VertexAttributeValues`](super::VertexAttributeValues) for a mesh.\n///\n/// It describes the order in which the vertex attributes should be joined into faces.\n#[derive(Debug, Clone, Reflect, PartialEq)]\n#[reflect(Clone)]\n#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\npub enum Indices {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_mesh/src/index.rs#L50-L86","documentation":"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.","triggerScenarios":"mesh.triangles() or mesh.triangles_mut() on a mesh whose primitive_topology() is PointList, LineList or LineStrip.","commonSituations":"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.","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"],"exampleFix":"// before\nlet tris: Vec<Triangle3d> = mesh.triangles()?.collect(); // Err(WrongTopology) on lines/points\n\n// after\nlet tris = if matches!(\n    mesh.primitive_topology(),\n    PrimitiveTopology::TriangleList | PrimitiveTopology::TriangleStrip\n) {\n    mesh.triangles()?.collect::<Vec<_>>()\n} else {\n    Vec::new()\n};","handlingStrategy":"validation","validationCode":"fn has_triangle_topology(mesh: &Mesh) -> bool {\n    matches!(\n        mesh.primitive_topology(),\n        PrimitiveTopology::TriangleList | PrimitiveTopology::TriangleStrip\n    )\n}\n\nif has_triangle_topology(&mesh) {\n    let tris: Vec<_> = mesh.triangles()?.collect();\n}","typeGuard":null,"tryCatchPattern":"match mesh.triangles() {\n    Ok(iter) => { /* iterate Triangle3d faces */ }\n    Err(MeshTrianglesError::WrongTopology) => { /* skip non-triangle meshes */ }\n    Err(other) => { /* positions/access errors */ }\n}","preventionTips":["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"],"tags":["bevy","bevy-mesh","rust","mesh","topology","triangles"],"backgroundTag":"mesh-topology-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}