{"record":{"id":"a3795ce363e1abc9","repo":"bevyengine/bevy","slug":"incorrect-number-of-weights-expected-expected","errorCode":null,"errorMessage":"Incorrect number of weights: expected {expected}, provided {provided}","messagePattern":"Incorrect number of weights: expected (.+?), provided (.+?)","errorType":"exception","errorClass":"CubicNurbsError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/cubic_splines/mod.rs","lineNumber":543,"sourceCode":"#[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,\n        /// Provided number of weights\n        provided: usize,\n    },\n    /// The number of control points provided is less than 4.\n    #[error(\"Not enough control points, at least 4 are required, {provided} were provided\")]\n    NotEnoughControlPoints {\n        /// The number of control points provided\n        provided: usize,\n    },\n}\n\n/// Non-uniform Rational B-Splines (NURBS) are a powerful generalization of the [`CubicBSpline`] which can\n/// represent a much more diverse class of curves (like perfect circles and ellipses).\n///\n/// ### Non-uniformity","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/cubic_splines/mod.rs#L525-L561","documentation":"CubicNurbsError::WeightsNumberMismatch is returned by CubicNurbs::new when the optional weights iterator yields a different count than the control points. Each NURBS control point must be paired with exactly one weight (rational basis), so a length mismatch makes the curve ill-defined. `expected` is the control-point count, `provided` is the weights count.","triggerScenarios":"CubicNurbs::new(points, Some(weights), knots) where weights.len() != points.len() — e.g. points filtered or appended after weights were built, or a weight list copied from a different asset.","commonSituations":"Editing a NURBS asset and removing a control point without touching weights; mixing per-segment weights with per-point weights; deserializing weights from JSON with a missing/extra element.","solutions":["Pass `None` for weights to get uniform weight 1.0 for every control point.","Make weights exactly control_points.len() long: pad with 1.0 or trim, depending on intent.","If weights come from data, validate lengths together at load time and reject the asset with a clear message."],"exampleFix":"// before\nlet points = vec![v0, v1, v2, v3, v4];\nlet weights = vec![1.0, 2.0, 1.0, 1.0]; // 4 weights, 5 points\nlet nurbs = CubicNurbs::new(points, Some(weights), None)?; // WeightsNumberMismatch\n\n// after\nlet points = vec![v0, v1, v2, v3, v4];\nlet weights = vec![1.0, 2.0, 1.0, 1.0, 1.0]; // one per point\nlet nurbs = CubicNurbs::new(points, Some(weights), None)?;","handlingStrategy":"validation","validationCode":"let ok = weights.as_ref().map_or(true, |w| w.len() == points.len());\nif !ok { /* pad/trim weights or pass None */ }","typeGuard":null,"tryCatchPattern":"match CubicNurbs::new(&points, Some(weights), knots) {\n    Ok(nurbs) => nurbs,\n    Err(CubicNurbsError::WeightsNumberMismatch { expected, provided }) => {\n        let fixed: Vec<f32> = (0..expected).map(|i| weights.get(i).copied().unwrap_or(1.0)).collect();\n        CubicNurbs::new(&points, Some(fixed), knots)?\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Store control points and weights together as Vec<(P, f32)> so they cannot diverge.","Default to `None` (uniform weights) unless rational behavior is required.","Validate serialized assets: weights.len() must equal points.len() before accepting the file."],"tags":["rust","bevy","math","spline","nurbs","runtime"],"backgroundTag":"invalid-spline-parameters","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"}