Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException on IsPlayingAndNotEnding #226

Closed
dots-alberto-uriarte opened this issue Sep 14, 2022 · 2 comments
Closed

NullReferenceException on IsPlayingAndNotEnding #226

dots-alberto-uriarte opened this issue Sep 14, 2022 · 2 comments
Labels
Bug Something isn't working Solved A solution is available here (but may not yet be included in the latest release)

Comments

@dots-alberto-uriarte
Copy link

Environment

  • Animancer Version Number: 7.3
  • Animancer Pro or Lite: Pro
  • Unity Version: 2019.4.35
  • Platform: iOS/Android

Description

NullReferenceException: Object reference not set to an instance of an object.
  at Animancer.AnimancerState.IsPlayingAndNotEnding () [0x00000] in <00000000000000000000000000000000>:0 
  at Cysharp.Threading.Tasks.EnumeratorAsyncExtensions+EnumeratorPromise+<ConsumeEnumerator>d__19.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at Cysharp.Threading.Tasks.EnumeratorAsyncExtensions+EnumeratorPromise.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at Cysharp.Threading.Tasks.Internal.PlayerLoopRunner.RunCore () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
  at Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1+<>c[TStateMachine].<.cctor>b__12_0 () [0<…>

The exception only appears on device, not on Editor. But on editor we noticed that if we await a Play(clip) on the same frame where we destroy the GameObject of the clip, the AnimancerState.IsPlayingAndNotEnding always returns true (which produce a "Task" leak).

Reproduction

I don't have an example scene to replicate the problem. But something similar to this would generate the problem:

public class AnimancerAsyncExample : MonoBehaviour
{
    [SerializeField] private AnimationClip _clip;
    [SerializeField] private int _animationLayer = 0;
    [SerializeField] private bool _isAdditive = false;
    [SerializeField] private AnimancerComponent _animancerComponent;

    private void OnDestroy()
    {
        AnimationOutAsync().Forget();
    }

    private async UniTaskVoid AnimationOutAsync()
    {
        _animancerComponent.Layers.SetAdditive(_animationLayer, _isAdditive);
        Debug.LogWarning("[Animancer] Animation out START");
        await _animancerComponent.Layers[_animationLayer].Play(_clip);
        Debug.LogWarning("[Animancer] Animation out END");
    }
}

Now destroying the object will cause a Task leak and "[Animancer] Animation out END" message never appears in the console.

Solution

At AnimancerState.IsPlayingAndNotEnding method add this early condition exit

if (!_Playable.IsValid())
{
    return false;
}
@dots-alberto-uriarte dots-alberto-uriarte added the Bug Something isn't working label Sep 14, 2022
@KybernetikGames KybernetikGames added the Solved A solution is available here (but may not yet be included in the latest release) label Sep 15, 2022
@KybernetikGames
Copy link
Owner

I agree that having IsPlayingAndNotEnding check _Playable.IsValid is reasonable so I've added it for the next version.

@KybernetikGames
Copy link
Owner

Animancer v7.4 is now available with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Solved A solution is available here (but may not yet be included in the latest release)
Projects
None yet
Development

No branches or pull requests

2 participants