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

  1. Provide at least 4 control points, e.g. duplicate end points to pad.
  2. For 2 points use LinearSpline, for interpolation through few points use Hermite or CubicBezier (point-interpolation) instead of NURBS.
  3. 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

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


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/30ea8defe70c0818. Report an issue: GitHub.