azchohfi / LottieUWP

UWP port of Lottie(https://github.com/airbnb/lottie-android)
Apache License 2.0
273 stars 45 forks source link

LottieView inside ListView DataTemplate causing random crash #32

Closed DazOz closed 5 years ago

DazOz commented 6 years ago

I have a ItemTemplate inside a listview. When loading my data via my ViewModel (3 rows) I receive the foloowing error. This is random and happens maybe 2 out of five times. Visually each animation is further along than the other,

image

Exception Message: System.Runtime.InteropServices.COMException: 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.CanvasControlOnDraw(ICanvasAnimatedControl canvasControl, CanvasAnimatedDrawEventArgs args)

DuncanKelbie commented 6 years ago

I get the exactly the same error, whenever I have multiple LottieAnimationViews all playing at the same time. The more there are the more likely it is to crash. It crashes on this line in Path.cs

image

andrewdewaal commented 5 years ago

The same error occurs for me when we have a template whose Lottie view is toggled between Visible and Collapsed.

System.Runtime.InteropServices.COMException: 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 System.Runtime.InteropServices.WindowsRuntime.IClosableToIDisposableAdapter.Dispose()  
at LottieUWP.LottieDrawable.Draw(CanvasDevice device, BitmapCanvas bitmapCanvas, CompositionLayer compositionLayer, Rect bounds, Single scale, Byte alpha,
azchohfi commented 5 years ago

It was really hard to debug this issue... It turns out that the Utils class ditn't handle multi-threading at all. I've fixed it.

andrewdewaal commented 5 years ago

Works great with 2.8.2 :) Thanks very much!