{"record":{"id":"92f4ebef1c78241a","repo":"bevyengine/bevy","slug":"need-at-least-two-unique-samples-to-create-a-chunk","errorCode":null,"errorMessage":"Need at least two unique samples to create a ChunkedUnevenCore, but {samples} were provided","messagePattern":"Need at least two unique samples to create a ChunkedUnevenCore, but (.+?) were provided","errorType":"exception","errorClass":"ChunkedUnevenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":492,"sourceCode":"    pub times: Vec<f32>,\n\n    /// The values that are used in sampling. Each width-worth of these correspond to a single sample.\n    ///\n    /// # Invariants\n    /// The length of this vector must always be some fixed integer multiple of that of `times`.\n    pub values: Vec<T>,\n}\n\n/// 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})\")]","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L474-L510","documentation":"ChunkedUnevenCoreError::NotEnoughSamples is returned by ChunkedUnevenCore::new / new_width_inferred when the times list, after filtering to finite values, sorting, and deduplication, contains fewer than 2 unique entries. Like UnevenCore, interpolation needs a span between two distinct times; the reported `samples` is the post-filter unique count.","triggerScenarios":"Passing times such as vec![0.0, 0.0, 0.0], times containing only NaN/INF entries, or a single timestamp; both constructors hit it via filter_sort_dedup_times before the length checks.","commonSituations":"All keyframes sharing one timestamp (same-frame events); NaN timestamps from upstream math; clock reset bugs that stamp every sample with time 0.0.","solutions":["Supply at least two distinct finite times.","Filter NaN/INF timestamps before calling and assert you still have >= 2 unique values.","Fix the time source if all timestamps collapse (e.g. delta-time accumulating as 0)."],"exampleFix":"// before\nlet core = ChunkedUnevenCore::new(vec![0.0, 0.0, 0.0], values, 3)?; // NotEnoughSamples { samples: 1 }\n\n// after\nlet core = ChunkedUnevenCore::new(vec![0.0, 0.5, 1.0], values, 3)?;","handlingStrategy":"validation","validationCode":"let unique_finite: Vec<f32> = {\n    let mut v: Vec<f32> = times.iter().copied().filter(f32::is_finite).collect();\n    v.sort_by(|a, b| a.total_cmp(b));\n    v.dedup();\n    v\n};\nif unique_finite.len() >= 2 {\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::NotEnoughSamples { samples }) => {\n        warn!(\"need >= 2 unique finite times, {samples} survived filtering\");\n        return Ok(());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Filter and dedup times before construction and assert >= 2 remain.","Investigate timestamp collapse early: identical frame times usually mean a stuck clock.","Sanitize NaN timestamps where they are produced, not where they are consumed."],"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"}