airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.92k stars 5.4k forks source link

Uncaught exception on Lottie that causes large canvas allocation #2478

Closed jasco closed 5 months ago

jasco commented 5 months ago

https://github.com/airbnb/lottie-android/blob/ae041af0f010523b5df68a5e6a8e3e5043f2054f/lottie/src/main/java/com/airbnb/lottie/model/layer/ImageLayer.java#L57

When too large a Lottie asset was declared, the Android platform was throwing an excess size runtime exception that would escape the Lottie library and crash the app. Catching RuntimeExceptions solved this problem.

try {
    canvas.drawBitmap(bitmap, src, dst, paint);
} catch (RuntimeException e) {
    Logger.error("Failed to drawBimap", e);
}

This was originally tested successfully in 6.0.0. Should I submit this as a PR? Unfortunately I no longer have a good test for this at hand. However I would love to get this patch applied.

gpeal commented 5 months ago

You can use the safeMode API instead. It is on LottieAnimationView, LottiDrawable, and the LottieAnimation composable.