Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lottie animation causing app crash on device

Tags:

swiftui

I am using Lottie to display animations in application and I tried to use this animation AnimationURL

LottieView -

struct LottieView: UIViewRepresentable {

var animationName: String

func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
    let view = UIView()
    return view
}

func updateUIView(_ uiView: UIViewType, context: Context) {
    let animationView = AnimationView()
    
    let animation = Animation.named(animationName)
    animationView.animation = animation
    animationView.contentMode = .scaleAspectFit
    animationView.backgroundBehavior = .pauseAndRestore
    animationView.loopMode = .loop
    
    animationView.translatesAutoresizingMaskIntoConstraints = false
    uiView.addSubview(animationView)
    
    NSLayoutConstraint.activate([
        animationView.heightAnchor.constraint(equalTo: uiView.heightAnchor),
        animationView.widthAnchor.constraint(equalTo: uiView.widthAnchor)
    ])
    
    animationView.play()
}
}

But when I want to display animation, application crashes in AnimatorNode file from Lottie library in this function (Thread 1: EXC_BAD_ACCESS (code=2, address=0x16ce6bff0)):

func updateContents(_ frame: CGFloat, forceLocalUpdate: Bool) -> Bool {
  guard isEnabled else {
      return parentNode?.updateContents(frame, forceLocalUpdate: forceLocalUpdate) ?? false
}
}

When I opened View Hierarchy after app crash, I received this log -

Failed to unarchive request data with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0}

On simulator, animation is running normally, but when I build application on device, application is crashing on this animation. Is there any way to fix this and use this animation?

like image 1000
Marko Markovic Avatar asked Sep 11 '25 22:09

Marko Markovic


1 Answers

We ran into the same issue. It doesn't depend on SwiftUI / UIKit thing. On Simulator it works ok because your simulator has more memory than iPhone does. So maybe your animation.json is too hard for current version of Lottie-ios lib. Maybe its good idea to report them, that they should update implementation of lib on iOS side. Thank you!

like image 170
Daniel Smith Avatar answered Sep 13 '25 17:09

Daniel Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!