Complete in callback cause unexpected behaviour
Akeit0 opened this issue · comments
Akeit0 commented
CallBack内で自身のhandleをCompleteさせると再帰してスタックオーバーフロー、
他のをhandleをCompleteさせるとOnCompleteActionが二回呼ばれます。
Akeit0 commented
こんな感じの用意した方がいいと思います。
public bool IsCallbackRunning { get;private set; }
public int RunningIndex;
public RunningMaker MarkRunning()=>new (this);
internal readonly struct RunningMaker : IDisposable
{
public RunningMaker(MotionStorage<TValue, TOptions, TAdapter> storage)
{
this.storage = storage;
storage.IsCallbackRunning = true;
}
readonly MotionStorage<TValue, TOptions, TAdapter> storage;
public void Dispose()
{
storage.IsCallbackRunning = false;
}
}
Akeit0 commented
if(!IsCallbackRunning)
{
float endProgress = motion.LoopType switch
{
LoopType.Restart => 1f,
LoopType.Yoyo => motion.Loops % 2 == 0 ? 0f : 1f,
LoopType.Incremental => motion.Loops,
_ => 1f
};
var endValue = default(TAdapter).Evaluate(
motion.StartValue,
motion.EndValue,
motion.Options,
new() { Progress = EaseUtility.Evaluate(endProgress, motion.Ease) }
);
callbacksArray[denseIndex].InvokeUnsafe(endValue);
callbacksArray[denseIndex].OnCompleteAction?.Invoke();
}
else if(RunningIndex==denseIndex)
{
callbacksArray[denseIndex].OnCompleteAction?.Invoke();
}
Akeit0 commented
このままで良ければPRします。
Annulus Games commented
おそらくその実装は複数Handleによる循環的な再帰呼び出しに対応できません。現在こちらで修正をほとんど終えているため、PRいただかなくても大丈夫です。
Annulus Games commented
#9 で修正済み