From 7d3795f745394d80df26d119b74ceb9ae25c6b6b Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Wed, 25 Mar 2026 20:29:39 -0400 Subject: [PATCH] Detect and replace NaNs in cXyz default ctor This fixes intermittent segfaults due to invalid atan table lookups. For some reason zero-initializing all cXyz objects causes issues, as does initializing them with INFINITY or -INFINITY. However, at least one of the possible crashes (in d_a_e_yg's search_ground_1) is guaranteed to happen whenever a specific uninitialized cXyz contains a NaN for x or z. A possible explanation for these crashes not occurring on hardware might be that the problematic objects happen to be placed at memory locations that happen to never contain a NaN upon allocation, so the buggy code was never caught. Further investigation would be needed to determine if this is what's actually happening, though. --- include/SSystem/SComponent/c_xyz.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/SSystem/SComponent/c_xyz.h b/include/SSystem/SComponent/c_xyz.h index 0bea35efe3..1f99737825 100644 --- a/include/SSystem/SComponent/c_xyz.h +++ b/include/SSystem/SComponent/c_xyz.h @@ -31,7 +31,17 @@ struct cXyz : Vec { z = vec.z; } #else - cXyz() = default; + cXyz() { + if (std::isnan(x)) { + x = 0.0f; + } + if (std::isnan(y)) { + y = 0.0f; + } + if (std::isnan(z)) { + z = 0.0f; + } + } ~cXyz() = default; cXyz(const cXyz& vec) = default; #endif