{"record":{"id":"29ebfc292da72df8","repo":"bevyengine/bevy","slug":"mesh-access-error-0-29ebfc","errorCode":null,"errorMessage":"mesh access error: {0}","messagePattern":"mesh access error: (.+?)","errorType":"exception","errorClass":"MeshTrianglesError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/index.rs","lineNumber":76,"sourceCode":"    /// * [`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 {\n    U16(Vec<u16>),\n    U32(Vec<u32>),\n}\n\nimpl Indices {\n    /// Returns an iterator over the indices.\n    pub fn iter(&self) -> impl Iterator<Item = usize> + '_ {\n        match self {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_mesh/src/index.rs#L58-L94","documentation":"MeshTrianglesError::MeshAccessError is the #[from] wrapper around MeshAccessError inside triangle extraction. triangles() calls try_attribute and try_indices, which fail with ExtractedToRenderWorld when the mesh's CPU-side vertex/index data has been moved to the RenderWorld because asset_usage excludes MAIN_WORLD.","triggerScenarios":"Calling mesh.triangles() on a mesh whose asset_usage is RenderAssetUsages::RENDER_WORLD only, after the render world has extracted the data.","commonSituations":"Runtime collision or picking systems reading triangles of memory-optimized meshes; mesh inspection tools running after extraction; assets shared between rendering and CPU physics without MAIN_WORLD.","solutions":["Set mesh.asset_usage to include RenderAssetUsages::MAIN_WORLD alongside RENDER_WORLD","Read triangle data before the mesh asset is rendered/extracted","Keep a separate CPU-side copy of geometry for physics/picking"],"exampleFix":"// before\nmesh.asset_usage = RenderAssetUsages::RENDER_WORLD;\nlet tris: Vec<Triangle3d> = mesh.triangles()?.collect(); // Err(ExtractedToRenderWorld)\n\n// after\nmesh.asset_usage = RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD;\nlet tris: Vec<Triangle3d> = mesh.triangles()?.collect();","handlingStrategy":"validation","validationCode":"fn mesh_readable_on_cpu(mesh: &Mesh) -> bool {\n    mesh.asset_usage.contains(RenderAssetUsages::MAIN_WORLD)\n}\n\nif mesh_readable_on_cpu(&mesh) {\n    let tris: Vec<_> = mesh.triangles()?.collect();\n}","typeGuard":null,"tryCatchPattern":"match mesh.triangles() {\n    Ok(iter) => { /* use triangles */ }\n    Err(MeshTrianglesError::MeshAccessError(\n        MeshAccessError::ExtractedToRenderWorld,\n    )) => { /* use a CPU-side copy of the geometry instead */ }\n    Err(other) => { /* topology / format / index errors */ }\n}","preventionTips":["Give physics/picking meshes asset_usage that includes MAIN_WORLD","Snapshot geometry before the mesh is rendered if it is needed later","Centralize asset_usage policy instead of setting it per mesh ad hoc"],"tags":["bevy","bevy-mesh","rust","mesh","asset-usage","render-world","triangles"],"backgroundTag":"mesh-data-extracted","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"}