bevyengine/bevy · error · IcosphereError
Cannot create an icosphere of {subdivisions} subdivisions du
Error message
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) What it means
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).
Source
Thrown at crates/bevy_mesh/src/primitives/dim3/sphere.rs:13
use crate::{Indices, Mesh, MeshBuilder, Meshable, PrimitiveTopology};
use bevy_asset::RenderAssetUsages;
use bevy_math::{ops, primitives::Sphere};
use bevy_reflect::prelude::*;
use core::f32::consts::PI;
use hexasphere::shapes::IcoSphere;
use thiserror::Error;
/// An error when creating an icosphere [`Mesh`] from a [`SphereMeshBuilder`].
#[derive(Clone, Copy, Debug, Error)]
pub enum IcosphereError {
/// The icosphere has too many vertices.
#[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)")]
TooManyVertices {
/// The number of subdivisions used. 79 is the largest allowed value for a mesh to be generated.
subdivisions: u32,
/// The number of vertices generated. 65535 is the largest allowed value for a mesh to be generated.
number_of_resulting_points: u32,
},
}
/// A type of sphere mesh.
#[derive(Clone, Copy, Debug, Reflect)]
#[reflect(Default, Debug, Clone)]
pub enum SphereKind {
/// An icosphere, a spherical mesh that consists of similar sized triangles.
Ico {
/// The number of subdivisions applied.
/// The number of faces quadruples with each subdivision.
subdivisions: u32,
},View on GitHub (pinned to 396ca72708)
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
Example fix
// before
let mesh = Sphere::new(1.0, SphereKind::Ico { subdivisions: 128 }).mesh().build(); // Err(TooManyVertices { subdivisions: 128, number_of_resulting_points: 166_412 })
// after
let mesh = Sphere::new(1.0, SphereKind::Ico { subdivisions: requested.min(79) }).mesh().build().unwrap(); Defensive patterns
Strategy: validation
Validate before calling
const MAX_ICO_SUBDIVISIONS: u32 = 79; // level 80 -> 10*81^2+2 = 65_612 > 65_535
let subdivisions = requested.min(MAX_ICO_SUBDIVISIONS);
let mesh = Sphere::new(radius, SphereKind::Ico { subdivisions }).mesh().build()?; Try / catch
match Sphere::new(1.0, SphereKind::Ico { subdivisions }).mesh().build() {
Ok(mesh) => mesh,
Err(IcosphereError::TooManyVertices { subdivisions, number_of_resulting_points }) => {
bevy::log::error!("{subdivisions} subdivisions -> {number_of_resulting_points} verts; clamping to 79");
Sphere::new(1.0, SphereKind::Ico { subdivisions: 79 }).mesh().build().unwrap()
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Bevy only supports up to {} morph targets (individual poses)
- The inner and outer meshes should have the same number of ve
- unsupported primitive mode
- failed to generate tangents: {0}
- failed to generate morph targets: {0}
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/6b8cdfadeb2ae1fe.
Report an issue: GitHub.