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

can't pause and set progress value manually #47

Open
Hanzalah-Adalan opened this issue Oct 20, 2018 · 6 comments
Open

can't pause and set progress value manually #47

Hanzalah-Adalan opened this issue Oct 20, 2018 · 6 comments

Comments

@Hanzalah-Adalan
Copy link

Unspecified error

Attempting to close a CanvasActiveLayer that is not top of the stack. The most recently created layer must be closed first.

at System.Runtime.InteropServices.WindowsRuntime.IClosable.Close()
at LottieUWP.LottieDrawable.Draw(CanvasDevice device, BitmapCanvas bitmapCanvas, CompositionLayer compositionLayer, Rect bounds, Single scale, Byte alpha, Matrix3X3 matrix, Double width, Double height, CanvasDrawingSession canvasDrawingSession)
at LottieUWP.LottieDrawable.CanvasControlOnDraw(ICanvasAnimatedControl canvasControl, CanvasAnimatedDrawEventArgs args)
@Hanzalah-Adalan
Copy link
Author

currently here's my noob solution: -> Reload the Json file altogether to start fresh otherwise I got those canvas's IClosable, IDisposable error stuffs..

 public async void PlayLottieDownload()
        {
            await LottieDownloadAnimation.SetAnimationAsync("Assets/Lottie/file_download.json");
            LottieDownloadAnimation.AutoPlay = true;
            LottieDownloadAnimation.PlayAnimation();
        }

        public async void StopLottieDownload()
        {
            await LottieDownloadAnimation.SetAnimationAsync("Assets/Lottie/file_download.json");
            LottieDownloadAnimation.Progress = 0.5f;
        }

@azchohfi
Copy link
Owner

What code did you use to try to pause and set the progress? And were that being called from the UI thread?

@Hanzalah-Adalan
Copy link
Author

I try to pause & set new progress value while it is active (animating) triggered by AutoPlay property set to True on App launch..

and Yes, that were being called from the UI thread.

I guess this is because there are two separate animations going on in this scenario, one from the AutoPlay trigger and another one from method call to pause and set the new value..

@HHChaos
Copy link
Contributor

HHChaos commented Oct 23, 2018

I also found this problem, some lottie files will crash if you change the Slider Value on LottieUWP.Sample. This bug is related to the CurrentDrawingSession of BitmapCanvas. I modified the Progress setter of LottieDrawable to avoid this bug.
@azchohfi If a crash Lottie file is needed, I can provide it.

code in LottieDrawable .cs

    public float Progress
    {
        get => _animator.AnimatedValueAbsolute;
        set
        {
            if (_composition == null)
            {
                _lazyCompositionTasks.Add(c => { Progress = value; });
                return;
            }
            //added code
            lock (this)
            {
                _bitmapCanvas?.Dispose();
                _bitmapCanvas = new BitmapCanvas(Width, Height);
            }

            Frame = MiscUtils.Lerp(_composition.StartFrame, _composition.EndFrame, value);
        }
    }

@azchohfi
Copy link
Owner

You are disposing the bitmapcanvas every frame change? I don't think that is a good solution.

@HHChaos
Copy link
Contributor

HHChaos commented Oct 24, 2018

      You are disposing the bitmapcanvas every frame change? I don't think that is a good solution.

The Progress setter of LottieDrawable is called only you changed the Slider value manually,and I didn't solve the bug, I just found a way to avoid it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants