From fd47b8d3b10302287128434c5ea040448b8c4ce5 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 22 Jan 2026 19:21:59 -0600 Subject: [PATCH] Enhance UnresolvedValue handling for CFrame and OptionalCFrame variants - Added checks to skip serialization for CFrames and OptionalCFrames with NaN values, improving data integrity during processing. - Introduced a new helper function `cframe_is_nan` to centralize NaN checks for CFrame values, enhancing code clarity and maintainability. - Updated the logic in `from_variant_unambiguous` to ensure that invalid CFrame values are not serialized, preventing potential errors in downstream processing. --- src/resolution.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/resolution.rs b/src/resolution.rs index 6ac290e3..afa8c5d9 100644 --- a/src/resolution.rs +++ b/src/resolution.rs @@ -89,9 +89,19 @@ impl UnresolvedValue { Variant::Color3(color) => { AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64]) } - Variant::CFrame(cf) => Self::cframe_to_array12(cf), + Variant::CFrame(cf) => { + if Self::cframe_is_nan(&cf) { + return None; + } + Self::cframe_to_array12(cf) + } Variant::OptionalCFrame(maybe_cf) => match maybe_cf { - Some(cf) => Self::cframe_to_array12(cf), + Some(cf) => { + if Self::cframe_is_nan(&cf) { + return None; + } + Self::cframe_to_array12(cf) + } None => return None, }, Variant::Attributes(attr) => AmbiguousValue::Attributes(attr), @@ -102,6 +112,13 @@ impl UnresolvedValue { } })) } else { + // Skip OptionalCFrame(None) and CFrames with NaN values to avoid serializing null arrays + match &variant { + Variant::OptionalCFrame(None) => return None, + Variant::OptionalCFrame(Some(cf)) if Self::cframe_is_nan(cf) => return None, + Variant::CFrame(cf) if Self::cframe_is_nan(cf) => return None, + _ => {} + } Some(Self::FullyQualified(variant)) } } @@ -123,6 +140,21 @@ impl UnresolvedValue { ]) } + fn cframe_is_nan(cf: &CFrame) -> bool { + cf.position.x.is_nan() + || cf.position.y.is_nan() + || cf.position.z.is_nan() + || cf.orientation.x.x.is_nan() + || cf.orientation.x.y.is_nan() + || cf.orientation.x.z.is_nan() + || cf.orientation.y.x.is_nan() + || cf.orientation.y.y.is_nan() + || cf.orientation.y.z.is_nan() + || cf.orientation.z.x.is_nan() + || cf.orientation.z.y.is_nan() + || cf.orientation.z.z.is_nan() + } + /// Creates an `UnresolvedValue` from a variant, only returning ambiguous /// values if they're able to be resolved in a context-free environment. pub fn from_variant_unambiguous(variant: Variant) -> Self {