bevyengine/bevy · error · EvenCoreError
Need at least two samples to create an EvenCore, but {sample
Error message
Need at least two samples to create an EvenCore, but {samples} were provided What it means
EvenCoreError::NotEnoughSamples is returned by EvenCore::new when fewer than 2 samples are provided. EvenCore interpolates between consecutive samples evenly spaced over a domain; with one sample there is nothing to interpolate between (the type documents a length >= 2 invariant on `samples`). `samples` reports the count you passed.
Source
Thrown at crates/bevy_math/src/curve/cores.rs:143
/// formed by interpolating them.
///
/// # Invariants
/// This must always be a bounded interval; i.e. its endpoints must be finite.
pub domain: Interval,
/// The samples that are interpolated to extract values.
///
/// # Invariants
/// This must always have a length of at least 2.
pub samples: Vec<T>,
}
/// An error indicating that an [`EvenCore`] could not be constructed.
#[derive(Debug, Error)]
#[error("Could not construct an EvenCore")]
pub enum EvenCoreError {
/// Not enough samples were provided.
#[error("Need at least two samples to create an EvenCore, but {samples} were provided")]
NotEnoughSamples {
/// The number of samples that were provided.
samples: usize,
},
/// Unbounded domains are not compatible with `EvenCore`.
#[error("Cannot create an EvenCore over an unbounded domain")]
UnboundedDomain,
}
#[cfg(feature = "alloc")]
impl<T> EvenCore<T> {
/// Create a new [`EvenCore`] from the specified `domain` and `samples`. The samples are
/// regarded to be evenly spaced within the given domain interval, so that the outermost
/// samples form the boundary of that interval. An error is returned if there are not at
/// least 2 samples or if the given domain is unbounded.
#[inline]
pub fn new(View on GitHub (pinned to 396ca72708)
Solutions
- Provide at least 2 samples — the outermost ones define the domain boundary.
- If you genuinely have one value, use a constant curve (e.g. ConstantCurve) instead of an interpolated core.
- Compute sample counts carefully: use a step that yields >= 2 points, or build samples with (0..=n) inclusive ranges.
Example fix
// before
let core = EvenCore::new(Interval::new(0.0, 1.0)?, vec![0.0f32]); // NotEnoughSamples { samples: 1 }
// after
let core = EvenCore::new(Interval::new(0.0, 1.0)?, vec![0.0f32, 1.0])?;
// or for a single value:
let curve = ConstantCurve::new(Interval::new(0.0, 1.0)?, 0.0f32); Defensive patterns
Strategy: validation
Validate before calling
if samples.len() >= 2 {
let core = EvenCore::new(domain, samples)?;
} Try / catch
let core = match EvenCore::new(domain, samples) {
Ok(core) => core,
Err(EvenCoreError::NotEnoughSamples { samples }) => {
debug_assert!(samples < 2);
return Ok(()); // or use ConstantCurve for a single value
}
Err(e) => return Err(e.into()),
}; Prevention
- Treat a single value as a constant, not a curve: reach for ConstantCurve.
- When generating samples from a range+step, verify the step yields >= 2 samples.
- Use inclusive ranges (0..=n) when computing sample counts to avoid off-by-one empties.
When it happens
Trigger: EvenCore::new(domain, vec![value]) or an empty vec; higher-level curve constructors (e.g. even-sample curves in bevy_math curve module) that forward a sample list which degenerated to a single element.
Common situations: Sampling a function at a single point; a slider/asset that yields one keyframe; generated sample lists where the count is computed as (end-start)/step and rounds to 1.
Related errors
- Not enough data to build curve: needed at least {expected} c
- Could not construct an EvenCore
- Cannot create an EvenCore over an unbounded domain
- Could not construct an UnevenCore
- Need at least two unique samples to create an UnevenCore, bu
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/66331c80f3370b51.
Report an issue: GitHub.