{"record":{"id":"6b8cdfadeb2ae1fe","repo":"bevyengine/bevy","slug":"cannot-create-an-icosphere-of-subdivisions-subdi","errorCode":null,"errorMessage":"Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)","messagePattern":"Cannot create an icosphere of (.+?) subdivisions due to there being too many vertices being generated: (.+?)\\. \\(Limited to 65535 vertices or 79 subdivisions\\)","errorType":"exception","errorClass":"IcosphereError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/primitives/dim3/sphere.rs","lineNumber":13,"sourceCode":"use crate::{Indices, Mesh, MeshBuilder, Meshable, PrimitiveTopology};\nuse bevy_asset::RenderAssetUsages;\nuse bevy_math::{ops, primitives::Sphere};\nuse bevy_reflect::prelude::*;\nuse core::f32::consts::PI;\nuse hexasphere::shapes::IcoSphere;\nuse thiserror::Error;\n\n/// An error when creating an icosphere [`Mesh`] from a [`SphereMeshBuilder`].\n#[derive(Clone, Copy, Debug, Error)]\npub enum IcosphereError {\n    /// The icosphere has too many vertices.\n    #[error(\"Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)\")]\n    TooManyVertices {\n        /// The number of subdivisions used. 79 is the largest allowed value for a mesh to be generated.\n        subdivisions: u32,\n        /// The number of vertices generated. 65535 is the largest allowed value for a mesh to be generated.\n        number_of_resulting_points: u32,\n    },\n}\n\n/// A type of sphere mesh.\n#[derive(Clone, Copy, Debug, Reflect)]\n#[reflect(Default, Debug, Clone)]\npub enum SphereKind {\n    /// An icosphere, a spherical mesh that consists of similar sized triangles.\n    Ico {\n        /// The number of subdivisions applied.\n        /// The number of faces quadruples with each subdivision.\n        subdivisions: u32,\n    },","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_mesh/src/primitives/dim3/sphere.rs#L1-L31","documentation":"IcosphereError::TooManyVertices (crates/bevy_mesh/src/primitives/dim3/sphere.rs:13) is returned by SphereMeshBuilder when icosphere subdivision would exceed the index budget. The check at sphere.rs:85 rejects subdivisions >= 80; an icosphere of level s generates 10*(s+1)^2 + 2 vertices, and level 80 would already produce 65,612 points, past the 65,535 (u16) ceiling the message documents (79 -> 64,002 vertices is the largest allowed).","triggerScenarios":"Building a mesh from Sphere::new(radius, SphereKind::Ico { subdivisions }) with subdivisions >= 80, or loading a serialized asset/config that carries such a value into the builder.","commonSituations":"UI sliders or config files driving subdivision level without bounds; copying a 'very smooth sphere' value from a forum post; deserializing untrusted scene parameters into SphereKind::Ico.","solutions":["Clamp subdivisions to <= 79 (e.g. subdivisions.min(79)) before building the mesh","Use SphereKind::Sphere { segments, rings } for extremely dense spheres — it is not subject to this icosphere cap","Validate the value at the config/asset boundary and reject out-of-range subdivisions with a clear message"],"exampleFix":"// before\nlet mesh = Sphere::new(1.0, SphereKind::Ico { subdivisions: 128 }).mesh().build(); // Err(TooManyVertices { subdivisions: 128, number_of_resulting_points: 166_412 })\n\n// after\nlet mesh = Sphere::new(1.0, SphereKind::Ico { subdivisions: requested.min(79) }).mesh().build().unwrap();","handlingStrategy":"validation","validationCode":"const MAX_ICO_SUBDIVISIONS: u32 = 79; // level 80 -> 10*81^2+2 = 65_612 > 65_535\n\nlet subdivisions = requested.min(MAX_ICO_SUBDIVISIONS);\nlet mesh = Sphere::new(radius, SphereKind::Ico { subdivisions }).mesh().build()?;","typeGuard":null,"tryCatchPattern":"match Sphere::new(1.0, SphereKind::Ico { subdivisions }).mesh().build() {\n    Ok(mesh) => mesh,\n    Err(IcosphereError::TooManyVertices { subdivisions, number_of_resulting_points }) => {\n        bevy::log::error!(\"{subdivisions} subdivisions -> {number_of_resulting_points} verts; clamping to 79\");\n        Sphere::new(1.0, SphereKind::Ico { subdivisions: 79 }).mesh().build().unwrap()\n    }\n}","preventionTips":["Clamp icosphere subdivisions to <= 79 wherever user or config input reaches SphereKind::Ico","Use SphereKind::Sphere { segments, rings } for extremely dense spheres","Validate deserialized primitive parameters before feeding mesh builders"],"tags":["bevy","mesh","primitives","icosphere","sphere","limit-exceeded"],"backgroundTag":"vertex-limit-exceeded","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}