{"record":{"id":"9db84a34bfa58c63","repo":"bevyengine/bevy","slug":"need-at-least-two-unique-samples-to-create-an-unev","errorCode":null,"errorMessage":"Need at least two unique samples to create an UnevenCore, but {samples} were provided","messagePattern":"Need at least two unique samples to create an UnevenCore, but (.+?) were provided","errorType":"exception","errorClass":"UnevenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":347,"sourceCode":"    ///\n    /// # Invariants\n    /// This must always have a length of at least 2, be sorted, and have no\n    /// duplicated or non-finite times.\n    pub times: Vec<f32>,\n\n    /// The samples corresponding to the times for this curve.\n    ///\n    /// # Invariants\n    /// This must always have the same length as `times`.\n    pub samples: Vec<T>,\n}\n\n/// An error indicating that an [`UnevenCore`] could not be constructed.\n#[derive(Debug, Error)]\n#[error(\"Could not construct an UnevenCore\")]\npub enum UnevenCoreError {\n    /// Not enough samples were provided.\n    #[error(\n        \"Need at least two unique samples to create an UnevenCore, but {samples} were provided\"\n    )]\n    NotEnoughSamples {\n        /// The number of samples that were provided.\n        samples: usize,\n    },\n}\n\n#[cfg(feature = \"alloc\")]\nimpl<T> UnevenCore<T> {\n    /// Create a new [`UnevenCore`]. The given samples are filtered to finite times and\n    /// sorted internally; if there are not at least 2 valid timed samples, an error will be\n    /// returned.\n    pub fn new(timed_samples: impl IntoIterator<Item = (f32, T)>) -> Result<Self, UnevenCoreError> {\n        // Filter out non-finite sample times first so they don't interfere with sorting/deduplication.\n        let mut timed_samples = timed_samples\n            .into_iter()\n            .filter(|(t, _)| t.is_finite())","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L329-L365","documentation":"UnevenCoreError::NotEnoughSamples is returned by UnevenCore::new when, after filtering out non-finite times, sorting, and deduplicating, fewer than 2 unique timed samples remain. Interpolation needs two distinct times to define a span. Note the count is post-processing, so 3 raw samples can still fail if two share a time and one is NaN.","triggerScenarios":"UnevenCore::new(vec![(0.0, a)]) with one sample; samples containing f32::NAN or f32::INFINITY timestamps that get filtered out; duplicated timestamps that dedup to a single unique time; empty input.","commonSituations":"Keyframe data with NaN times produced by upstream math (0/0, acos out of range); timestamp collisions from two events in the same frame; deserialized animation data where times failed to parse and defaulted to the same value.","solutions":["Ensure at least two samples with distinct, finite f32 times before constructing.","Sanitize times: replace or drop NaN/INF timestamps at load time with an explicit policy.","If timestamps can legitimately collide, aggregate them (e.g. keep the last) before building the core."],"exampleFix":"// before\nlet core = UnevenCore::new(vec![ (0.0, a), (f32::NAN, b), (0.0, c) ])?; // NotEnoughSamples { samples: 1 }\n\n// after\nlet times_samples: Vec<(f32, V)> = raw\n    .into_iter()\n    .filter(|(t, _)| t.is_finite())\n    .collect();\nassert!(times_samples.len() >= 2, \"need >= 2 unique finite times\");\nlet core = UnevenCore::new(times_samples)?;","handlingStrategy":"validation","validationCode":"let cleaned: Vec<(f32, T)> = timed.into_iter().filter(|(t, _)| t.is_finite()).collect();\nlet unique_times = cleaned.iter().map(|(t, _)| t.to_bits()).collect::<std::collections::HashSet<_>>();\nif unique_times.len() >= 2 {\n    let core = UnevenCore::new(cleaned)?;\n}","typeGuard":null,"tryCatchPattern":"let core = match UnevenCore::new(timed_samples) {\n    Ok(core) => core,\n    Err(UnevenCoreError::NotEnoughSamples { samples }) if samples == 0 => {\n        return Ok(()); // nothing recorded yet this frame; skip\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Filter NaN/INF timestamps at the source (asset load, sensor read) rather than relying on the core to drop them.","Deduplicate same-timestamp samples yourself if collisions are expected.","Debug_assert on time sources that produce identical timestamps repeatedly (clock not advancing)."],"tags":["rust","bevy","math","curve","nan","runtime"],"backgroundTag":"insufficient-curve-samples","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"}