From d9ca3e5b57df31bbb0116369f6de166c5df1a8c6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 5 Jan 2024 11:29:53 +0100 Subject: [PATCH] Add sanity check to prevent crashes when Animated Model has NaN in skeleton pose #2118 --- Source/Engine/Animations/Graph/AnimGraph.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Source/Engine/Animations/Graph/AnimGraph.cpp b/Source/Engine/Animations/Graph/AnimGraph.cpp index 5aa720d31..7c4671a51 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.cpp +++ b/Source/Engine/Animations/Graph/AnimGraph.cpp @@ -282,6 +282,20 @@ void AnimGraphExecutor::Update(AnimGraphInstanceData& data, float dt) } } } +#if !BUILD_RELEASE + { + // Perform sanity check on nodes pose to prevent crashes due to NaNs + bool anyInvalid = animResult->RootMotion.IsNanOrInfinity(); + for (int32 i = 0; i < animResult->Nodes.Count(); i++) + anyInvalid |= animResult->Nodes.Get()[i].IsNanOrInfinity(); + if (anyInvalid) + { + LOG(Error, "Animated Model pose contains NaNs due to animations sampling/blending bug."); + context.Data = nullptr; + return; + } + } +#endif SkeletonData* animResultSkeleton = &skeleton; // Retarget animation when using output pose from other skeleton