{"record":{"id":"4f5805d30056833d","repo":"bevyengine/bevy","slug":"chunk-width-must-be-at-least-1","errorCode":null,"errorMessage":"Chunk width must be at least 1","messagePattern":"Chunk width must be at least 1","errorType":"exception","errorClass":"ChunkedUnevenCoreError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/curve/cores.rs","lineNumber":488,"sourceCode":"    ///\n    /// # Invariants\n    /// This must always have a length of at least 2, be sorted, and have no duplicated or\n    /// non-finite times.\n    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,","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/curve/cores.rs#L470-L506","documentation":"ChunkedUnevenCoreError::ZeroWidth is returned by ChunkedUnevenCore::new when `width` is 0. The width is the number of values per sample time (the chunk size); zero would mean samples carry no data, and it also makes the values-length check meaningless (any length matches 0 times n). new_width_inferred can hit it too when values is empty.","triggerScenarios":"ChunkedUnevenCore::new(times, values, 0) — width often computed as values.len() / times.len() with integer division that floors to 0; new_width_inferred with an empty values list.","commonSituations":"Dynamically computing width from data whose sizes are mismatched; template/generic code where the sample dimension type is empty; asset loaders receiving an empty channel buffer.","solutions":["Pass width >= 1 — for vector samples it is the vector dimension.","Fix the width computation: check `values.len()` against processed (filtered/deduped) times, not raw times, and guard the division.","If values is legitimately empty, skip curve construction entirely."],"exampleFix":"// before\nlet width = values.len() / times.len(); // floors to 0 when len(times) > len(values)\nlet core = ChunkedUnevenCore::new(times, values, width)?; // ZeroWidth\n\n// after\nlet width = sample_dim; // known vector dimension, e.g. Vec3 => 3\nlet core = ChunkedUnevenCore::new(times, values, width)?;","handlingStrategy":"validation","validationCode":"assert!(width >= 1, \"chunk width must be at least 1\");\nif width >= 1 {\n    let core = ChunkedUnevenCore::new(times, values, width)?;\n}","typeGuard":null,"tryCatchPattern":"let core = match ChunkedUnevenCore::new(times, values, width) {\n    Ok(core) => core,\n    Err(ChunkedUnevenCoreError::ZeroWidth) => {\n        ChunkedUnevenCore::new(times, values, 1)? // treat samples as scalars\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Take width from the sample type's dimension (Vec2 => 2, Vec3 => 3) instead of deriving it by division.","Guard any `values.len() / times.len()` computation against a zero result.","Reject empty values buffers at asset load before attempting construction."],"tags":["rust","bevy","math","curve","runtime"],"backgroundTag":"invalid-chunk-width","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}