airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.76k stars 3.75k forks source link

`LottieLogger.assertFailure` should not crash in Release build. #1663

Closed blastmann closed 2 years ago

blastmann commented 2 years ago

Which Version of Lottie are you using?

Lottie 3.3.0

Expected Behavior

LottieLogger.shared().assertFailure should not trigger in Release build. Assertion should be filtered.

Actual Behavior

It crashes when assertFailure happened. Did not work as expected.

Demo

latest.zip

calda commented 2 years ago

LottieLogger.shared.assertionFailure defaults to the built-in stdlib assertionFailure function, which does not terminate the process in release builds:

This function’s effect varies depending on the build flag used:

  • In playgrounds and -Onone builds (the default for Xcode’s Debug configuration), stop program execution in a debuggable state after printing message.
  • In -O (release) builds, has no effect.

Is your release build using -Onone? If not, but you're still experiencing a crash in release builds, could you share a sample project that reproduces the issue?

You can always customize the behavior of LottieLogger.shared to suit the needs of your project. For example you could have it always just log to the console instead of calling assertionFailure by setting LottieLogger.shared = .printToConsole.

calda commented 2 years ago

Ah I just noticed that you had attached a sample project. Thanks!

This does seem unexpected -- I don't understand why it crashes when you call LottieLogger.shared.assertionFailure but not Swift.assertionFailure, considering the Lottie logger assertion implementation literally is Swift.assertionFailure:

assertionFailure: @escaping AssertionFailure = Swift.assertionFailure,

if I change the LottieLogger init to instead be:

assertionFailure: @escaping AssertionFailure = { message, file, line in 
  Swift.assertionFailure(message(), file: file, line: line) 
},

then the crash goes away. This seems pretty bizarre.

calda commented 2 years ago

Haha wow ok, this is weird for sure. LottieLogger.shared.assertionFailure crashes in release but LottieLogger().assertionFailure doesn't. I'll make the change above on master to workaround this issue, thank you for the report!

calda commented 2 years ago

I filed a compiler bug for this, since it seems unexpected: https://github.com/apple/swift/issues/60249

blastmann commented 2 years ago

Thank you so much!

calda commented 2 years ago

This is fixed in today's 3.4.1 release by the way 👍🏻

chaoxcheng commented 1 year ago

This is fixed in today's 3.4.1 release by the way 👍🏻

this bug not fixed in 4.2.0 release when I use: ´ func position(for keyPath: String) -> CGPoint { let kp = AnimationKeypath(sgKeypath: "(keyPath).Transform.Position") guard let vector = getValue(for: kp, atFrame: nil) as? LottieVector3D else { return CGPoint.zero } return CGPoint(x: vector.sizeValue.width, y: vector.sizeValue.height) } ´ image image