bevyengine/bevy · error · ChunkedUnevenCoreError

The length of the list of values ({values_len}) was not divi

Error message

The length of the list of values ({values_len}) was not divisible by that of the list of times ({times_len})

What it means

ChunkedUnevenCoreError::NonDivisibleLengths is returned only by ChunkedUnevenCore::new_width_inferred when values.len() is not an integer multiple of the processed (finite, sorted, deduplicated) times count. Width inference divides values length by times count; a non-divisible ratio means no consistent chunk size exists. `values_len`/`times_len` show the two lengths used.

Source

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

    #[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")]
impl<T> ChunkedUnevenCore<T> {
    /// Create a new [`ChunkedUnevenCore`]. The given `times` are sorted, filtered to finite times,
    /// and deduplicated. See the [type-level documentation] for more information about this type.
    ///
    /// Produces an error in any of the following circumstances:
    /// - `width` is zero.
    /// - `times` has less than `2` unique valid entries.
    /// - `values` has the incorrect length relative to `times`.
    ///

View on GitHub (pinned to 396ca72708)

Solutions

  1. Use new_width_inferred only when you know values.len() == k * unique_finite_times_len for some integer k; otherwise call new() with the explicit width.
  2. Validate divisibility at load time: `values.len() % unique_times != 0` -> reject the asset with a clear message.
  3. Recount times the same way the core does: filter non-finite, sort, dedup, then compare.

Example fix

// before
let times = vec![0.0, 0.0, 1.0, 2.0]; // 3 unique after dedup
let values = vec![1.0, 2.0, 3.0, 4.0]; // 4 not divisible by 3
let core = ChunkedUnevenCore::new_width_inferred(times, values)?; // NonDivisibleLengths { values_len: 4, times_len: 3 }

// after
let times = vec![0.0, 0.0, 1.0, 2.0]; // 3 unique
let values = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]; // 6 = width 2 * 3
let core = ChunkedUnevenCore::new_width_inferred(times, values)?; // width inferred as 2
Defensive patterns

Strategy: validation

Validate before calling

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 !t.is_empty() && values.len() % t.len() == 0 {
    let core = ChunkedUnevenCore::new_width_inferred(times, values)?;
} else {
    // use new() with an explicit width instead
}

Try / catch

match ChunkedUnevenCore::new_width_inferred(times, values) {
    Ok(core) => core,
    Err(ChunkedUnevenCoreError::NonDivisibleLengths { values_len, times_len }) => {
        warn!("{values_len} values not divisible by {times_len} unique times");
        return Ok(());
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: new_width_inferred(times, values) where values.len() % processed_times.len() != 0 — e.g. 7 values for 3 unique times, or values sized against raw times after dedup removed duplicates (4 values, 2 unique times is fine, but 6 values against 4 unique times is not).

Common situations: Flattened vector data whose dimension doesn't divide evenly (7 floats treated as 3D vectors plus a stray element); duplicate timestamps removed by the core making the raw ratio wrong; switching from new() to new_width_inferred without re-checking data assumptions.

Related errors


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