bevyengine/bevy · error · CubicNurbsError
Not enough control points, at least 4 are required, {provide
Error message
Not enough control points, at least 4 are required, {provided} were provided What it means
CubicNurbsError::NotEnoughControlPoints is returned by CubicNurbs::new when fewer than 4 control points are provided. A cubic (degree-3) B-spline segment needs 4 control points minimum; below that there is no cubic segment to solve for. `provided` reports how many points you actually passed.
Source
Thrown at crates/bevy_math/src/cubic_splines/mod.rs:551
provided: usize,
},
/// The provided knots had a descending knot pair. Subsequent knots must
/// either increase or stay the same.
#[error("Invalid knots: contains descending knot pair")]
DescendingKnots,
/// The provided knots were all equal. Knots must contain at least one increasing pair.
#[error("Invalid knots: all knots are equal")]
ConstantKnots,
/// Provided a different number of weights and control points.
#[error("Incorrect number of weights: expected {expected}, provided {provided}")]
WeightsNumberMismatch {
/// Expected number of weights
expected: usize,
/// Provided number of weights
provided: usize,
},
/// The number of control points provided is less than 4.
#[error("Not enough control points, at least 4 are required, {provided} were provided")]
NotEnoughControlPoints {
/// The number of control points provided
provided: usize,
},
}
/// Non-uniform Rational B-Splines (NURBS) are a powerful generalization of the [`CubicBSpline`] which can
/// represent a much more diverse class of curves (like perfect circles and ellipses).
///
/// ### Non-uniformity
///
/// The 'NU' part of NURBS stands for "Non-Uniform". This has to do with a parameter called 'knots'.
/// The knots are a non-decreasing sequence of floating point numbers. The first and last three pairs of
/// knots control the behavior of the curve as it approaches its endpoints. The intermediate pairs
/// each control the length of one segment of the curve. Multiple repeated knot values are called
/// "knot multiplicity". Knot multiplicity in the intermediate knots causes a "zero-length" segment,
/// and can create sharp corners.
///View on GitHub (pinned to 396ca72708)
Solutions
- Provide at least 4 control points, e.g. duplicate end points to pad.
- For 2 points use LinearSpline, for interpolation through few points use Hermite or CubicBezier (point-interpolation) instead of NURBS.
- Guard runtime-built lists: branch to a different curve type when points.len() < 4.
Example fix
// before
let nurbs = CubicNurbs::new(vec![p0, p1, p2], None, None)?; // NotEnoughControlPoints
// after
let curve = if points.len() >= 4 {
CubicNurbs::new(points.iter().copied(), None, None)?.to_curve()?.into()
} else {
LinearSpline::new(points.iter().copied()).to_curve()?.into()
}; Defensive patterns
Strategy: validation
Validate before calling
if points.len() < 4 {
// pick a lower-degree fallback instead of calling CubicNurbs::new
} Try / catch
let curve = match CubicNurbs::new(&points, None, None) {
Ok(nurbs) => nurbs.to_curve()?,
Err(CubicNurbsError::NotEnoughControlPoints { .. }) => {
LinearSpline::new(points.clone()).to_curve()? // graceful downgrade for short lists
}
Err(e) => return Err(e.into()),
}; Prevention
- Branch on points.len() before choosing the spline type: >= 4 -> NURBS/BSpline, 2-3 -> Linear/Hermite.
- Pad short lists by duplicating endpoints when a NURBS specifically is required.
- Unit-test curve builders with 0, 1, and 3 point inputs.
When it happens
Trigger: CubicNurbs::new(vec![p0, p1, p2], ...) with 3 or fewer points; dynamically built point lists that can be short at runtime (empty spawn lists, single sample from input).
Common situations: Prototyping with 2-3 clicked points in an editor; edge-case runtime data (a path with one waypoint); tests with minimal fixtures.
Related errors
- Invalid knots: all knots are equal
- Incorrect number of weights: expected {expected}, provided {
- Not enough data to build curve: needed at least {expected} c
- Wrong number of knots: expected {expected}, provided {provid
- Invalid knots: contains descending knot pair
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/30ea8defe70c0818.
Report an issue: GitHub.