This scml results in NaN being returned by MathHelper's GetFactormethod when animation time reaches animation length (i.e. Time property in Animator is 1200 and deltaTime passed to Animate is nonzero) due to division by zero. This happens due to combination of duplicate key being at the end of animation and first key being at the start of it.
Step by step:
FrameDataCalculator.GetFrameData calls SpriterHelper.AdjustTime. Passed keyA is key with id 6, keyB is key with id 0
SpriterHelper.AdjustTime calls SpriterHelper.GetFactor, passed keys are the same
In SpriterHelper.GetFactor calculated timeA is equal to timeB after this if statement.
I've implemented the fix though would like to confirm first that this is a bug since the fix goes beyond fixing the problematic if statement in SpriterHelper as there are other places I had to change to remove this division by zero:
Calculation of nextTime inside SpriterHelper.AdjustTime should consider the case of keyB distant from keyA by animation length and being before it.
FrameDataCalculator.GetMainlineKeys has to be updated not to return pair of duplicate keys but return keys with different timeline position.
SpriterHelper.GetNextKey should not return duplicate key.
Found the case by using SpriterDotNetUnity - Unity reported errors like due to this.
transform.localPosition assign attempt for *** is not valid. Input localPosition is { NaN, NaN, 0.000000 }.
According to Spriter staff, it's valid to have duplicate key in the timeline. Imagine having following timeline:
This scml results in
NaN
being returned byMathHelper
'sGetFactor
method when animation time reaches animation length (i.e.Time
property inAnimator
is 1200 anddeltaTime
passed toAnimate
is nonzero) due to division by zero. This happens due to combination of duplicate key being at the end of animation and first key being at the start of it.Step by step:
FrameDataCalculator.GetFrameData
callsSpriterHelper.AdjustTime
. PassedkeyA
is key with id 6,keyB
is key with id 0SpriterHelper.AdjustTime
callsSpriterHelper.GetFactor
, passed keys are the sameSpriterHelper.GetFactor
calculatedtimeA
is equal totimeB
after this if statement.I've implemented the fix though would like to confirm first that this is a bug since the fix goes beyond fixing the problematic if statement in
SpriterHelper
as there are other places I had to change to remove this division by zero:nextTime
insideSpriterHelper.AdjustTime
should consider the case ofkeyB
distant fromkeyA
by animation length and being before it.FrameDataCalculator.GetMainlineKeys
has to be updated not to return pair of duplicate keys but return keys with different timeline position.SpriterHelper.GetNextKey
should not return duplicate key.Found the case by using SpriterDotNetUnity - Unity reported errors like due to this.