{"record":{"id":"11d2d28ec97f6366","repo":"bevyengine/bevy","slug":"cannot-interpolate-between-two-arrays-of-different","errorCode":null,"errorMessage":"cannot interpolate between two arrays of different lengths","messagePattern":"cannot interpolate between two arrays of different lengths","errorType":"exception","errorClass":"VecInterpolateError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/common_traits.rs","lineNumber":633,"sourceCode":"\nimpl<T: StableInterpolate> TryStableInterpolate for T {\n    type Error = Infallible;\n    fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result<Self, Self::Error> {\n        Ok(self.interpolate_stable(other, t))\n    }\n\n    fn try_interpolate_stable_assign(&mut self, other: &Self, t: f32) -> Result<(), Self::Error> {\n        self.interpolate_stable_assign(other, t);\n        Ok(())\n    }\n}\n\n/// Errors produced when interpolating dynamically-sized arrays\n#[cfg(feature = \"alloc\")]\n#[derive(Clone, Debug, Error)]\npub enum VecInterpolateError<E> {\n    /// Produced when arrays to be interpolated are of different lengths\n    #[error(\"cannot interpolate between two arrays of different lengths\")]\n    MismatchedLength,\n    /// Produced when an error occurs interpolating an array element\n    #[error(transparent)]\n    Inner(E),\n}\n\n#[cfg(feature = \"alloc\")]\nimpl<E, T: TryStableInterpolate<Error = E>> TryStableInterpolate for alloc::vec::Vec<T> {\n    type Error = VecInterpolateError<E>;\n    fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result<Self, Self::Error> {\n        if self.len() == other.len() {\n            (0..self.len())\n                .map(|i| self[i].try_interpolate_stable(&other[i], t))\n                .collect::<Result<alloc::vec::Vec<_>, _>>()\n                .map_err(VecInterpolateError::Inner)\n        } else {\n            Err(VecInterpolateError::MismatchedLength)\n        }","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/common_traits.rs#L615-L651","documentation":"Vec<T>'s TryStableInterpolate requires self and other to have equal lengths; a length difference returns MismatchedLength, while element-level failures are wrapped in Inner(E) (crates/bevy_math/src/common_traits.rs:633). Interpolating element-wise between arrays of different sizes has no defined result, so it fails instead of guessing.","triggerScenarios":"Calling try_interpolate_stable on two Vecs whose lengths differ — e.g. captured lists of styles or transforms where entries were added or removed between the two snapshots.","commonSituations":"Animating lists of UI children whose count changed mid-animation; diff-based tween systems capturing start/end states at different times; serde-loaded sequences that drift in length.","solutions":["Compare lengths before interpolating; re-capture both endpoints whenever the count changes.","On MismatchedLength, snap to the target Vec instead of blending.","Handle Inner(e) separately for element-level failures such as MismatchedUnitsError."],"exampleFix":"// before\nlet blended = a.try_interpolate_stable(&b, t).unwrap(); // panics when lengths differ\n\n// after\nlet blended = if a.len() == b.len() {\n    a.try_interpolate_stable(&b, t).unwrap_or_else(|_| b.clone())\n} else {\n    b.clone()\n};","handlingStrategy":"validation","validationCode":"use bevy_math::TryStableInterpolate;\n\nfn can_blend<T: TryStableInterpolate>(a: &Vec<T>, b: &Vec<T>) -> bool {\n    a.len() == b.len()\n}\n\nlet blended = if can_blend(&a, &b) {\n    a.try_interpolate_stable(&b, t).unwrap_or_else(|_| b.clone())\n} else {\n    b.clone()\n};","typeGuard":null,"tryCatchPattern":"match a.try_interpolate_stable(&b, t) {\n    Ok(v) => { /* use v */ }\n    Err(VecInterpolateError::MismatchedLength) => { /* snap to b */ }\n    Err(VecInterpolateError::Inner(e)) => { /* handle element error e */ }\n}","preventionTips":["Re-capture both endpoint snapshots when a list's length changes.","Compare lengths before interpolating dynamic collections.","Handle Inner errors separately — they wrap element-level failures like unit mismatches."],"tags":["bevy","math","interpolation","vec","length-mismatch","animation"],"backgroundTag":"array-length-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}