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

Fix discard render job before changing _animation or _texture #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Runtime/UI/ImageLottiePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected override void OnDisable()

protected override void OnDestroy()
{
DiscardRenderJob();
DestroyImmediate(_texture);
_animation.Dispose();
base.OnDestroy();
Expand Down Expand Up @@ -142,7 +143,9 @@ protected void RecreateAnimationIfNeeded()
{
return;
}
else if (_animationAsset.CacheKey != _lastAnimationAssetCacheKey)

DiscardRenderJob();
if (_animationAsset.CacheKey != _lastAnimationAssetCacheKey)
{
_animation.Dispose();
_lastAnimationAssetCacheKey = _animationAsset.CacheKey;
Expand All @@ -168,6 +171,7 @@ protected void RecreateAnimationIfNeeded()

protected void RenderNow()
{
DiscardRenderJob();
_animation.Render(_currentFrame, _texture, keepAspectRatio: false);
_texture.Apply(true);
}
Expand All @@ -184,6 +188,11 @@ protected void CompleteRenderJob()
_texture.Apply(true);
}

protected void DiscardRenderJob()
{
_renderJobHandle.Complete();
}

#if UNITY_EDITOR
protected override void OnValidate()
{
Expand Down