bevyengine/bevy · error · ChunkedUnevenCoreError

Expected {expected} total values based on width, but {actual

Error message

Expected {expected} total values based on width, but {actual} were provided

What it means

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.

Source

Thrown at crates/bevy_math/src/curve/cores.rs:501

/// An error that indicates that a [`ChunkedUnevenCore`] could not be formed.
#[derive(Debug, Error)]
#[error("Could not create a ChunkedUnevenCore")]
pub enum ChunkedUnevenCoreError {
    /// The width of a `ChunkedUnevenCore` cannot be zero.
    #[error("Chunk width must be at least 1")]
    ZeroWidth,

    /// At least two sample times are necessary to interpolate in `ChunkedUnevenCore`.
    #[error(
        "Need at least two unique samples to create a ChunkedUnevenCore, but {samples} were provided"
    )]
    NotEnoughSamples {
        /// The number of samples that were provided.
        samples: usize,
    },

    /// The length of the value buffer is supposed to be the `width` times the number of samples.
    #[error("Expected {expected} total values based on width, but {actual} were provided")]
    MismatchedLengths {
        /// The expected length of the value buffer.
        expected: usize,
        /// The actual length of the value buffer.
        actual: usize,
    },

    /// Tried to infer the width, but the ratio of lengths wasn't an integer, so no such length exists.
    #[error("The length of the list of values ({values_len}) was not divisible by that of the list of times ({times_len})")]
    NonDivisibleLengths {
        /// The length of the value buffer.
        values_len: usize,
        /// The length of the time buffer.
        times_len: usize,
    },
}

#[cfg(feature = "alloc")]

View on GitHub (pinned to 396ca72708)

Solutions

  1. Filter values together with times (drop the value whenever you drop its time) so lengths stay in lockstep.
  2. Use the formula: values.len() must equal (number of unique finite times) * width.
  3. Prefer building Vec<(f32, Vec<T>)> pairs first, then splitting, so indices can never drift.

Example fix

// before
let times = vec![0.0, f32::NAN, 1.0];        // raw len 3
let values = vec![v0a, v0b, v0c, v1a, v1b, v1c, v2a, v2b, v2c]; // sized for 3 times
let core = ChunkedUnevenCore::new(times, values, 3)?; // MismatchedLengths { expected: 6, actual: 9 }

// after
let timed: Vec<(f32, [T; 3])> = raw.into_iter().filter(|(t, _)| t.is_finite()).collect();
let (times, chunks): (Vec<f32>, Vec<T>) = timed
    .into_iter()
    .flat_map(|(t, v)| std::iter::once(t).chain(v))
    .unzip_or_collect(); // conceptually: times and flattened values stay paired
let core = ChunkedUnevenCore::new(times, chunks, 3)?;
Defensive patterns

Strategy: validation

Validate before calling

// mirror the core's preprocessing, then check lengths
let mut t: Vec<f32> = times.iter().copied().filter(f32::is_finite).collect();
t.sort_by(|a, b| a.total_cmp(b));
t.dedup();
if values.len() == t.len() * width {
    let core = ChunkedUnevenCore::new(times, values, width)?;
}

Try / catch

match ChunkedUnevenCore::new(times, values, width) {
    Ok(core) => core,
    Err(ChunkedUnevenCoreError::MismatchedLengths { expected, actual }) => {
        warn!("values len {actual}, expected {expected} (= width {width} * unique finite times)");
        return Ok(());
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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