Skip to content

lottie crashed in AnimationContainer.init() on iOS9 device when used Xcode11.4 #1155

Closed
@EmilLiu

Description

@EmilLiu

When I compiled and ran with the latest version of Xcode 11.4, there was a crash anywhere I used Lottie on iOS 9 devices

Check these before submitting:

  • [✔️] The issue doesn't involve an Unsupported Feature
  • [✔️] This issue isn't related to another open issue

This issue is a:

  • [] Non-Crashing Bug (Visual or otherwise)
  • [✔️] Crashing Bug
  • [] Feature Request
  • [] Regression (Something that once worked, but doesn't work anymore)

Which Version of Lottie are you using?

Lottie 3.1.6

What Platform are you on?

  • [] MacOS
  • [✔️] iOS

What Language are you in?

  • [✔️] Swift
  • [] Objective-C

Expected Behavior

Actual Behavior

Code Example

Animation JSON

Activity

robaggio

robaggio commented on Mar 30, 2020

@robaggio

Same for me, only iOS 9 devices will crash, the same code on Xcode 11.3 is OK.

Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1976e8160 objc_release + 16
1 Lottie 0x101d7cdac specialized AnimationContainer.init(animation:imageProvider:textProvider:) + 608 (:608)
2 Lottie 0x101d84358 AnimationView.makeAnimationLayer() + 268 (AnimationContainer.swift:268)
3 Lottie 0x101d83de4 AnimationView.animation.setter + 76 (:76)

robaggio

robaggio commented on Mar 30, 2020

@robaggio

The example project in the repo can reproduce the crash, with Xcode 11.4 on an iOS 9 device. Change the deployment target to 9.0 first.

frank-du

frank-du commented on Apr 1, 2020

@frank-du

Same for me, only iOS 9 devices will crash, the same code on Xcode 11.3 is OK.

Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1976e8160 objc_release + 16
1 Lottie 0x101d7cdac specialized AnimationContainer.init(animation:imageProvider:textProvider:) + 608 (:608)
2 Lottie 0x101d84358 AnimationView.makeAnimationLayer() + 268 (AnimationContainer.swift:268)
3 Lottie 0x101d83de4 AnimationView.animation.setter + 76 (:76)

Same for me

hakonk

hakonk commented on Apr 1, 2020

@hakonk

Can confirm this problem on iOS 9 with Xcode 11.4 as well. Enabling Zombie Objects in Xcode 11.4 results in the following output before crashing the application: *** -[Lottie.AnimationContainer release]: message sent to deallocated instance 0x<address>

brunsman

brunsman commented on Apr 1, 2020

@brunsman

Same problem here. I blame the changed embedding of frameworks in Xcode 11.4. Downgraded to Xcode 11.3 for now and waiting for Apple to fix the embedding of frameworks.

hakonk

hakonk commented on Apr 2, 2020

@hakonk

@brunsman Do you have more details on what the change in embedding of frameworks entails?

brunsman

brunsman commented on Apr 15, 2020

@brunsman

After digging into the issue more, I can now isolate the issue to something else. Will post the same here for reference, see https://forums.developer.apple.com/thread/131551

The code seems related to Xcode 11.4, ios 9 devices, and custom CALayers with properties.

To see this problem, Create an extension of an CALayer:

class CustomLayer: CALayer {  
   var someProperty: CGFloat = 0  
}

Now programmatically create such a layer, e.g. in a viewDidLoad

let customLayer = CustomLayer()

Compile and run this on a iOS 9 device (my tests were with an iPhone 4S with iOS 9.3.6). The device crashes when initializing the layer. It is deallocated BEFORE it can actually set the property on the customLayer. Enable zombies for a more detailed stack trace.

Since lottie uses custom CALayers with properties, it now crashes on iOS 9 devices when using Xcode 11.4. Hoping for a fix or workaround from Apple. Filed a bug report about it.

hakonk

hakonk commented on Apr 15, 2020

@hakonk

Great work @brunsman ! Looking forward to hearing the about the response.

hakonk

hakonk commented on Apr 15, 2020

@hakonk

@brunsman I tried to circumvent the initializer of CALayer in Swift by making a simple category for CALayer in Objective-C:

CALayer+Init.h

#import <QuartzCore/QuartzCore.h>

NS_ASSUME_NONNULL_BEGIN

@interface CALayer (Init)
+(instancetype)newInstance;
@end

NS_ASSUME_NONNULL_END

CALayer+Init.m

#import "CALayer+Init.h"

@implementation CALayer (Init)
+(instancetype)newInstance {
    return [[CALayer alloc] init];
}
@end

Making use of the class method in this category seems to work.

class CustomLayer: CALayer {
    var someProperty: CGFloat = 0
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let customLayer = CustomLayer.newInstance() // this seems to work
        let customLayer2 = CustomLayer() // <- this still crashes
        view.layer.addSublayer(customLayer)
        view.layer.addSublayer(customLayer)
    }
}

Edit:

Unfortunately, trying to access the property on CustomLayer after making use of the class method in the category mentioned above, I get a runtime error: "Thread 1: EXC_BAD_ACCESS (code=2, address=0x.......)"

Interestingly, changing the property to be a let instead of var, does not lead to a crash. I.e.:

class CustomLayer: CALayer {
    let someProperty: CGFloat = 0
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let customLayer = CustomLayer()
        view.layer.addSublayer(customLayer)
    }
}
brunsman

brunsman commented on Apr 15, 2020

@brunsman

@hakonk If you find a workaround, that would be great! So far, no dice.

Edit: XCode 11.4.1 also does not fix this issue. Still waiting for a response from Apple.

hakonk

hakonk commented on Apr 16, 2020

@hakonk

@brunsman The approach above with the Objective-C category is flawed for sure. My colleagues have pointed me in the direction of reading up on CALayer and the magic that happens under the hood, so I'll do that when I have time.

I attempted to make use of Objective-C's runtime capabilities (associated objects) to implement a property on a subclass of CALayer:

class CustomLayer: CALayer {
    private static var somePropertyHandle = 0
    var someProperty: CGFloat {
        get {
            guard let val = objc_getAssociatedObject(
                self,
                &CustomLayer.somePropertyHandle
            ) as? CGFloat else { fatalError("No obj found") }
            return val
        }
        set {
            objc_setAssociatedObject(
                self,
                &CustomLayer.somePropertyHandle,
                newValue,
                objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC
            )
        }
    }
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let customLayer = CustomLayer()
        // needs to be assigned, or else the computed property logic will crash
        customLayer.someProperty = 123
        print(customLayer.someProperty)
        view.layer.addSublayer(customLayer)
    }
}

While it works, it's a cumbersome and somewhat hacky approach for just implementing a simple property.

brunsman

brunsman commented on May 7, 2020

@brunsman

Reported the bug to apple on the 15th of april. Got an update from Apple:

Custom CALayer with properties crashes on iOS 9 devices
15 april 2020, 8:36 AM — FB7664233
Recent Similar Reports: Less than 10
Resolution: Potential fix identified - For a future OS update

Hoping for this best and that the new xCode will fix the problem...

falcon283

falcon283 commented on May 18, 2020

@falcon283

XCode 11.5 GM is out and the release notes state:

Fixed an issue with incorrect code generation when targeting armv7 devices. (61901594)

Is it the bug we are hunting?
Anyone have chance to test it?

Many thanks

hakonk

hakonk commented on May 19, 2020

@hakonk

@falcon283 @brunsman
I tried compiling and running with Xcode Version 11.5 (11E608c) and I'm still getting -[Lottie.AnimationContainer release]: message sent to deallocated instance (Zombie objects enabled).

falcon283

falcon283 commented on May 19, 2020

@falcon283

@falcon283 @brunsman

I tried compiling and running with Xcode Version 11.5 (11E608c) and I'm still getting -[Lottie.AnimationContainer release]: message sent to deallocated instance (Zombie objects enabled).

Thanks a lot for the feedback @hakonk

10 remaining items

hakonk

hakonk commented on Oct 6, 2020

@hakonk

Wow, that's a bummer, @brunsman! Anyway, it's interesting to know that the issue is still open.

zhiliang729

zhiliang729 commented on Oct 20, 2020

@zhiliang729

xcode 12.0.1 still crash !!!!!!!!!!

sonnt612

sonnt612 commented on Oct 30, 2020

@sonnt612

How to fix this?

sonnt612

sonnt612 commented on Oct 30, 2020

@sonnt612

xcode 12.1 still crash

robaggio

robaggio commented on Oct 30, 2020

@robaggio

Maybe it is time to consider dropping support for iOS9 in your app.

Mervin1024

Mervin1024 commented on Nov 25, 2020

@Mervin1024

same to me. xcode 12.0

chengyang1380

chengyang1380 commented on Feb 9, 2021

@chengyang1380

Xcode 12.3 still crash. 😥

FunnyerFeng

FunnyerFeng commented on Feb 26, 2021

@FunnyerFeng

截屏2021-02-26 上午11 27 37
Version 12.4 (12D4e)

xperiatrix

xperiatrix commented on Feb 27, 2021

@xperiatrix

I switched to a gif animation in Kingfisher's AnimatedImageView only on iOS9 instead of lottie's way .

brunsman

brunsman commented on May 20, 2021

@brunsman

From Apple:

Thanks for your update. We have additional information.

The compiler can shrink lifetimes of objects in case an object is not used at a certain point.
This is an optimization and it can definitely be that this optimization is not performed in an older compiler version, but it is performed in a newer compiler version. This would explain why the crash does not show up when compiling with an older Xcode version.

If this is the case with customLayer, a fix would be to use withExtendedLifetime to ensure that customLayer is not deleted until the end of the specified lifetime.
For details see: https://developer.apple.com/documentation/swift/1541033-withextendedlifetime

I haven't tested whether this works since we stopped using iOS 9. Perhaps it can be used by others.

yaochenfeng

yaochenfeng commented on Jul 30, 2021

@yaochenfeng

也许用OC实现CALayer的子类,Swift中使用,iOS10以上就不用这样了

Viveco

Viveco commented on Jan 26, 2022

@Viveco

use xib crah, need code xcode 12.3 ios9 lottie 3.2.1

Feng999

Feng999 commented on Feb 28, 2022

@Feng999

anything new?
Xcode 13.2.1, the problem is still there

calda

calda commented on Jul 13, 2022

@calda
Member

Closing since Lottie no longer supports iOS 9 (the minimum deployment version is now iOS 11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @robaggio@manuhook@rizerco@falcon283@calda

        Issue actions

          lottie crashed in AnimationContainer.init() on iOS9 device when used Xcode11.4 · Issue #1155 · airbnb/lottie-ios