Merge pull request #509 from Cysharp/ku/fix-dotween-registration
Fix a bug in Dotween after returning to the pool of `CancellationToken.Register`master
commit
a46a4cac01
|
@ -148,6 +148,7 @@ namespace Cysharp.Threading.Tasks
|
|||
Tween tween;
|
||||
TweenCancelBehaviour cancelBehaviour;
|
||||
CancellationToken cancellationToken;
|
||||
CancellationTokenRegistration cancellationRegistration;
|
||||
CallbackType callbackType;
|
||||
bool canceled;
|
||||
|
||||
|
@ -207,7 +208,7 @@ namespace Cysharp.Threading.Tasks
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (result.originalCompleteAction == result.onCompleteCallbackDelegate)
|
||||
{
|
||||
result.originalCompleteAction = null;
|
||||
|
@ -215,7 +216,7 @@ namespace Cysharp.Threading.Tasks
|
|||
|
||||
if (cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationToken.RegisterWithoutCaptureExecutionContext(x =>
|
||||
result.cancellationRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(x =>
|
||||
{
|
||||
var source = (TweenConfiguredSource)x;
|
||||
switch (source.cancelBehaviour)
|
||||
|
@ -250,30 +251,7 @@ namespace Cysharp.Threading.Tasks
|
|||
source.tween.Complete(true);
|
||||
break;
|
||||
case TweenCancelBehaviour.CancelAwait:
|
||||
// restore to original callback
|
||||
switch (callbackType)
|
||||
{
|
||||
case CallbackType.Kill:
|
||||
tween.onKill = source.originalCompleteAction;
|
||||
break;
|
||||
case CallbackType.Complete:
|
||||
tween.onComplete = source.originalCompleteAction;
|
||||
break;
|
||||
case CallbackType.Pause:
|
||||
tween.onPause = source.originalCompleteAction;
|
||||
break;
|
||||
case CallbackType.Play:
|
||||
tween.onPlay = source.originalCompleteAction;
|
||||
break;
|
||||
case CallbackType.Rewind:
|
||||
tween.onRewind = source.originalCompleteAction;
|
||||
break;
|
||||
case CallbackType.StepComplete:
|
||||
tween.onStepComplete = source.originalCompleteAction;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
source.RestoreOriginalCallback();
|
||||
source.core.TrySetCanceled(source.cancellationToken);
|
||||
break;
|
||||
}
|
||||
|
@ -376,7 +354,18 @@ namespace Cysharp.Threading.Tasks
|
|||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
core.Reset();
|
||||
cancellationRegistration.Dispose();
|
||||
|
||||
RestoreOriginalCallback();
|
||||
|
||||
tween = default;
|
||||
cancellationToken = default;
|
||||
originalCompleteAction = default;
|
||||
return pool.TryPush(this);
|
||||
}
|
||||
|
||||
void RestoreOriginalCallback()
|
||||
{
|
||||
switch (callbackType)
|
||||
{
|
||||
case CallbackType.Kill:
|
||||
|
@ -400,11 +389,6 @@ namespace Cysharp.Threading.Tasks
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
tween = default;
|
||||
cancellationToken = default;
|
||||
originalCompleteAction = default;
|
||||
return pool.TryPush(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue