From 60fd4702a626241ef80293250f7be083ee9decb5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 5 Jan 2024 11:52:28 +0100 Subject: [PATCH] Fix crash when using degenerated triangle in Multi Blend 2D to properly sample animation #2118 --- .../Animations/Graph/AnimGroup.Animation.cpp | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 8a7751ecb..1058ea301 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1367,33 +1367,29 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu } // Use 1D blend if points are on the same line (degenerated triangle) - // TODO: simplify this code + struct BlendData + { + float AlphaX, AlphaY; + Animation* AnimA, *AnimB; + const Float4* AnimAd, *AnimBd; + }; + BlendData blendData; if (v1.Y >= v0.Y) { if (p.Y < v0.Y && v1.Y >= v0.Y) - { - const float alpha = p.Y / v0.Y; - value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, aAnim, bAnim, aData.W, bData.W, alpha); - } + blendData = { p.Y, v0.Y, aAnim, bAnim, &aData, &bData }; else - { - const float alpha = (p.Y - v0.Y) / (v1.Y - v0.Y); - value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, bAnim, cAnim, bData.W, cData.W, alpha); - } + blendData = { p.Y - v0.Y, v1.Y - v0.Y, bAnim, cAnim, &bData, &cData }; } else { if (p.Y < v1.Y) - { - const float alpha = p.Y / v1.Y; - value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, aAnim, cAnim, aData.W, cData.W, alpha); - } + blendData = { p.Y, v1.Y, aAnim, cAnim, &aData, &cData }; else - { - const float alpha = (p.Y - v1.Y) / (v0.Y - v1.Y); - value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, cAnim, bAnim, cData.W, bData.W, alpha); - } + blendData = { p.Y - v1.Y, v0.Y - v1.Y, cAnim, bAnim, &cData, &bData }; } + const float alpha = Math::IsZero(blendData.AlphaY) ? 0.0f : blendData.AlphaX / blendData.AlphaY; + value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, blendData.AnimA, blendData.AnimB, blendData.AnimAd->W, blendData.AnimBd->W, alpha); } else {