{"record":{"id":"8ce5cac62e62dbc2","repo":"bevyengine/bevy","slug":"wrong-number-of-knots-expected-expected-provid","errorCode":null,"errorMessage":"Wrong number of knots: expected {expected}, provided {provided}","messagePattern":"Wrong number of knots: expected (.+?), provided (.+?)","errorType":"exception","errorClass":"CubicNurbsError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/cubic_splines/mod.rs","lineNumber":528,"sourceCode":"        // since it means the first segment doesn't go \"between\" the first two control points, but\n        // between the second and third instead.\n\n        if segments.is_empty() {\n            Err(InsufficientDataError {\n                expected: 2,\n                given: self.control_points.len(),\n            })\n        } else {\n            Ok(CubicCurve { segments })\n        }\n    }\n}\n\n/// Error during construction of [`CubicNurbs`]\n#[derive(Clone, Debug, Error)]\npub enum CubicNurbsError {\n    /// Provided the wrong number of knots.\n    #[error(\"Wrong number of knots: expected {expected}, provided {provided}\")]\n    KnotsNumberMismatch {\n        /// Expected number of knots\n        expected: usize,\n        /// Provided number of knots\n        provided: usize,\n    },\n    /// The provided knots had a descending knot pair. Subsequent knots must\n    /// either increase or stay the same.\n    #[error(\"Invalid knots: contains descending knot pair\")]\n    DescendingKnots,\n    /// The provided knots were all equal. Knots must contain at least one increasing pair.\n    #[error(\"Invalid knots: all knots are equal\")]\n    ConstantKnots,\n    /// Provided a different number of weights and control points.\n    #[error(\"Incorrect number of weights: expected {expected}, provided {provided}\")]\n    WeightsNumberMismatch {\n        /// Expected number of weights\n        expected: usize,","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/cubic_splines/mod.rs#L510-L546","documentation":"CubicNurbs::new requires exactly control_points.len() + 4 knots (cubic degree plus one); any other count returns KnotsNumberMismatch with the expected and provided numbers (cubic_splines/mod.rs:655-663).","triggerScenarios":"Passing a hand-built or imported knot vector whose length does not equal n + 4 where n is the control point count — e.g. after changing the point list without regenerating knots.","commonSituations":"Converting NURBS data from tools that use different degree conventions; hand-authoring knot arrays; editing control points without updating the knot vector.","solutions":["Size the knot vector to control_points.len() + 4 before calling CubicNurbs::new.","Pass None for knots to have open uniform knots generated automatically.","Regenerate knots whenever the control point list changes length."],"exampleFix":"// before\nlet nurbs = CubicNurbs::new(pts, None, Some(knots))?; // knots.len() != pts.len() + 4\n\n// after\nassert_eq!(knots.len(), pts.len() + 4);\nlet nurbs = CubicNurbs::new(pts, None, Some(knots))?;\n// or let Bevy generate valid knots:\nlet nurbs = CubicNurbs::new(pts, None, None)?;","handlingStrategy":"validation","validationCode":"use bevy_math::CubicNurbs;\n\nfn knots_valid_len(n_points: usize, knots: &[f32]) -> bool {\n    knots.len() == n_points + 4\n}\n\n// pass None instead of hand-building knots when in doubt:\nlet nurbs = CubicNurbs::new(points, None, None)?;","typeGuard":null,"tryCatchPattern":"match CubicNurbs::new(points, weights, Some(knots)) {\n    Err(CubicNurbsError::KnotsNumberMismatch { expected, provided }) => {\n        // resize/regenerate the knot vector to expected\n    }\n    Ok(n) => { /* use n */ }\n    Err(e) => warn!(\"{e}\"),\n}","preventionTips":["Compute knot count as points.len() + 4 rather than hardcoding.","Regenerate knots whenever the control point list changes.","Prefer passing None for knots unless you need custom parameterization."],"tags":["bevy","math","spline","nurbs","knots","validation"],"backgroundTag":"spline-knot-count-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}