{"record":{"id":"b3ea681378b8e873","repo":"bevyengine/bevy","slug":"expected-expected-total-values-based-on-width-b","errorCode":null,"errorMessage":"Expected {expected} total values based on width, but {actual} were provided","messagePattern":"Expected (.+?) total values based on width, but (.+?) were provided","errorType":"exception","errorClass":"ChunkedUnevenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":501,"sourceCode":"/// An error that indicates that a [`ChunkedUnevenCore`] could not be formed.\n#[derive(Debug, Error)]\n#[error(\"Could not create a ChunkedUnevenCore\")]\npub enum ChunkedUnevenCoreError {\n    /// The width of a `ChunkedUnevenCore` cannot be zero.\n    #[error(\"Chunk width must be at least 1\")]\n    ZeroWidth,\n\n    /// At least two sample times are necessary to interpolate in `ChunkedUnevenCore`.\n    #[error(\n        \"Need at least two unique samples to create a ChunkedUnevenCore, but {samples} were provided\"\n    )]\n    NotEnoughSamples {\n        /// The number of samples that were provided.\n        samples: usize,\n    },\n\n    /// The length of the value buffer is supposed to be the `width` times the number of samples.\n    #[error(\"Expected {expected} total values based on width, but {actual} were provided\")]\n    MismatchedLengths {\n        /// The expected length of the value buffer.\n        expected: usize,\n        /// The actual length of the value buffer.\n        actual: usize,\n    },\n\n    /// Tried to infer the width, but the ratio of lengths wasn't an integer, so no such length exists.\n    #[error(\"The length of the list of values ({values_len}) was not divisible by that of the list of times ({times_len})\")]\n    NonDivisibleLengths {\n        /// The length of the value buffer.\n        values_len: usize,\n        /// The length of the time buffer.\n        times_len: usize,\n    },\n}\n\n#[cfg(feature = \"alloc\")]","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L483-L519","documentation":"ChunkedUnevenCoreError::MismatchedLengths is returned by ChunkedUnevenCore::new when values.len() != times.len() * width. The trap: the expected length is computed against the PROCESSED times (finite-filtered, sorted, deduplicated), not the raw list you passed — so dropping a NaN or duplicate time changes the required values count. `expected` = width * processed_times_len, `actual` = your values length.","triggerScenarios":"ChunkedUnevenCore::new(times, values, width) where values was sized to the raw times list but filtering removed an entry (NaN/duplicate time), or width doesn't match the per-sample chunk size used to build values.","commonSituations":"Pairing times and values arrays loaded from separate asset channels; sanitizing times (dropping invalid entries) without dropping their corresponding values; mixing up row-major flattening dimensions.","solutions":["Filter values together with times (drop the value whenever you drop its time) so lengths stay in lockstep.","Use the formula: values.len() must equal (number of unique finite times) * width.","Prefer building Vec<(f32, Vec<T>)> pairs first, then splitting, so indices can never drift."],"exampleFix":"// before\nlet times = vec![0.0, f32::NAN, 1.0];        // raw len 3\nlet values = vec![v0a, v0b, v0c, v1a, v1b, v1c, v2a, v2b, v2c]; // sized for 3 times\nlet core = ChunkedUnevenCore::new(times, values, 3)?; // MismatchedLengths { expected: 6, actual: 9 }\n\n// after\nlet timed: Vec<(f32, [T; 3])> = raw.into_iter().filter(|(t, _)| t.is_finite()).collect();\nlet (times, chunks): (Vec<f32>, Vec<T>) = timed\n    .into_iter()\n    .flat_map(|(t, v)| std::iter::once(t).chain(v))\n    .unzip_or_collect(); // conceptually: times and flattened values stay paired\nlet core = ChunkedUnevenCore::new(times, chunks, 3)?;","handlingStrategy":"validation","validationCode":"// mirror the core's preprocessing, then check lengths\nlet mut t: Vec<f32> = times.iter().copied().filter(f32::is_finite).collect();\nt.sort_by(|a, b| a.total_cmp(b));\nt.dedup();\nif values.len() == t.len() * width {\n    let core = ChunkedUnevenCore::new(times, values, width)?;\n}","typeGuard":null,"tryCatchPattern":"match ChunkedUnevenCore::new(times, values, width) {\n    Ok(core) => core,\n    Err(ChunkedUnevenCoreError::MismatchedLengths { expected, actual }) => {\n        warn!(\"values len {actual}, expected {expected} (= width {width} * unique finite times)\");\n        return Ok(());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Keep times and values as Vec<(f32, Vec<T>)> pairs and flatten only at the call, so filtered times always take their values with them.","Remember the expected length uses post-filter unique times, not your raw times count.","Add a load-time assertion: values.len() == unique_finite_times * width."],"tags":["rust","bevy","math","curve","length-mismatch","runtime"],"backgroundTag":"values-times-length-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}