Baseflow / LottieXamarin

Render After Effects animations natively on Android, iOS, MacOS and TvOS for Xamarin
https://baseflow.com
Apache License 2.0
1.22k stars 261 forks source link

[iOS] NullReferenceException in AnimationCompletionBlock #345

Closed JosueDM94 closed 3 years ago

JosueDM94 commented 3 years ago

šŸ› Bug Report

iOS Apps are crashing with NullReferenceException when using Lottie Animation on the root page and then the root page is updated when the animation finishes, Android is working as expected.

Expected behavior

The iOS App should not crash when the animation finishes and the Root Page is updated.

Reproduction steps

Retro Steps: 1.- Set a ContentPage with an AnimationView as a MainPage. 2.- Wait until Animation finishes, then update the MainPage with a new ContantPage. 3.- iOS App crash with NullReferenceException

Repro Solution: LottieCrash.zip

Exception Info: Exception: System.NullReferenceException Message: Object reference not set to an instance of an object Source: Lottie.Forms StackTrace: at Lottie.Forms.Platforms.Ios.AnimationViewRenderer.AnimationCompletionBlock (System.Boolean animationFinished) [0x00022] in Z:\Documents\OpenSource\LottieXamarin\Lottie.Forms\Platforms\Ios\AnimationViewRenderer.cs:195 at ObjCRuntime.Trampolines+SDLOTAnimationCompletionBlock.Invoke (System.IntPtr block, System.Boolean animationFinished) [0x00016] in /Users/martijn/Documents/OpenSource/LottieXamarin/Lottie.iOS/obj/Release/xamarin.ios10/ios/ObjCRuntime/Trampolines.g.cs:70 at (wrapper native-to-managed) ObjCRuntime.Trampolines+SDLOTAnimationCompletionBlock.Invoke(intptr,int) at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65 at LottieCrash.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jdiaz/Projects/LottieCrash/LottieCrash.iOS/Main.cs:17

Configuration

Version: 4.0.10

Platform:

tozik commented 3 years ago

The same issue with me for version 4.0.9 with Xamarin.Forms for iOS platform. Also some times handling AnimationViewRenderer+<>c__DisplayClass4_0.b__3 ()

martinhey commented 3 years ago

have the same problem when adding an EventToCommandBehaviour which navigates to another content page

I temporarily solved it with waiting for 1 second in the resulting command to ensure the AnimationCompletionBlock has been finisehd before navigating. But it would be better to check for null again in line 195 or completely change the order of the statements

roubachof commented 3 years ago

Same issue here line 195, null check is missing. For now we can just override the renderer in ios and apply the null check ourselves. Nope we can't cause the renderer use extensively internal properties making it impossible to override.

roubachof commented 3 years ago

same issue with version 4.0.10.

roubachof commented 3 years ago

After Element.InvokeFinishedAnimation, the Element can be null. So we need to check if Element == null before the if blocks.

image

sidv24 commented 3 years ago

I'm using Lottie.Forms (via Xamarin.Forms). I can see the animation but it is not playing. Searching it through a bit I realized I am not using AnimationViewRenderer.Init(). But using Lottie.Forms.Platforms.Ios; is not showing AnimationViewRenderer.Init(), it does show AnimationViewRenderer but it doesn't have Init() function. Please help!