azchohfi / LottieUWP

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

Crash: Attempting to close a CanvasActiveLayer #50

Open DirtyNative opened 5 years ago

DirtyNative commented 5 years ago

When showing and hiding a View which contains a LottieAnimationView, the application sometimes crashes giving the error WinRT information: Attempting to close a CanvasActiveLayer that is not top of the stack. The most recently created layer must be closed first.

This happens randomly to me

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, Matrix3X3 matrix, Double width, Double height, CanvasDrawingSession canvasDrawingSession) at LottieUWP.LottieDrawable.CanvasControlOnDraw(ICanvasAnimatedControl canvasControl, CanvasAnimatedDrawEventArgs args) at Windows.ApplicationModel.Core.UnhandledError.Propagate() at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object sender, UnhandledErrorDetectedEventArgs eventArgs) --- End of stack trace from previous location where exception was thrown --- at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object sender, UnhandledErrorDetectedEventArgs eventArgs)

andrewdewaal commented 5 years ago

If this is the same as the error from problem 32, then this would be fixed with version 2.8.2.

azchohfi commented 5 years ago

@DirtyNative could you check if this is fixed on 2.8.2?

DirtyNative commented 5 years ago

Version 2.8.2 does not seem to be published on Nuget, so I will do as soon as it is.

azchohfi commented 5 years ago

It is. It was pushed 8 days ago: https://www.nuget.org/packages/LottieUWP/2.8.2 Are you having any problems with this version?

DirtyNative commented 5 years ago

Sorry my fault, it is released. I am still getting this error, but not as often as before.

azchohfi commented 5 years ago

We have support for symbols and source link in this version. Could you try to disable "Just my code" on VS's Debug options and add the NuGet symbol server? This should give you a more detailed stack whenever the exception throws.

In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).

Under Symbol file (.pdb) locations, add a new symbol server location by selecting the + symbol in the toolbar. Use the following URL https://symbols.nuget.org/download/symbols.

DirtyNative commented 5 years ago

This still does not show me the line where the exception happens, the debugger just jumps to my App.g.i.cs file which is an autogenerated file.

azchohfi commented 5 years ago

I don't think you enabled the debugging correctly, or you are not using 2.8.2. Which version of VS you are using?

michaels-screenovate commented 5 years ago

I had the same exception. I believe the problem is setting multiple time the FileName property. A possible scenario that would crash:

  1. Set file name A to LottieView instance 1. Play video and discard lottie instance => file name A is in the lottie cache.
  2. Set file name B to LottieView instance 2 (which in my case was an invalid file). => Lottie attempts to load file name B.
  3. Set file name A to LottieView instance 2. => loading file A completes before processing of file name B completes (because file A is already in the cache).
  4. Start animation.
  5. Processing of file B completes, apparently screwing something in the loaded file A.
  6. LottieDrawable crashes in Draw(). (Strangely it seems like Draw run one time successfully and in the second time it crashes when drawing the layer.

`Exception thrown at 0x00007FFCAC2DA388 (KernelBase.dll) in BluePhoneUniversalClient.exe: WinRT originate error - 0x80004005 : '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.Draw(CanvasDevice device, BitmapCanvas bitmapCanvas, CompositionLayer compositionLayer, Rect bounds, Single scale, Byte alpha, Matrix3X3 matrix, Double width, Double height, CanvasDrawingSession canvasDrawingSession)'.`

NikhStash commented 5 years ago

I am facing this issue in 2.8.2 build. It is based on json file I use. Some json files it doesn't happen at all. Some it happens every time. Both are valid json files, and the same files work in IOS and Android.

azchohfi commented 5 years ago

@michaels-screenovate don't use this anymore. Use https://github.com/windows-toolkit/Lottie-Windows

vanalmelo commented 5 years ago

@NikhStash I'm experiencing this exact issue, and sadly I cannot just use a different toolkit because of OS limitations.

Have you figured out anything about why some JSON files do/don't work? I don't generate these files, I'm just implementing, so my knowledge about this is very limited.

azchohfi commented 5 years ago

Some files use specific features that just are not implemented.

0ptim commented 5 years ago

I'm having simillar issues. Sadly this is no longer supported and developers have to switch over to the windows toolkit version. In itself not a bad thing but it isn't obvious that everyone can just switch to the newest platform target version.