Skip to content

Commit

Permalink
Check composition exists when using software rendering (#2025)
Browse files Browse the repository at this point in the history
To reproduce crash, add the following to the IssueReproActivity:
```
binding.animationView.setCacheComposition(false)
binding.animationView.renderMode = RenderMode.SOFTWARE
binding.animationView.postDelayed({ binding.animationView.setAnimation(R.raw.heart) }, 1000)
```

When it tries to render with null composition, `getIntrinsicWidth()` and `getIntrinsicHeight()` return `-1`, and both `renderWidth` and `renderHeight` end up being negative, which results in a crash:
```
    java.lang.IllegalArgumentException: width must be > 0
        at android.graphics.Bitmap.checkWidthHeight(Bitmap.java:378)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:684)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:653)
        at com.airbnb.lottie.LottieDrawable.ensureSoftwareRenderingBitmap(LottieDrawable.java:1452)
        at com.airbnb.lottie.LottieDrawable.renderAndDrawAsBitmap(LottieDrawable.java:1400)
        at com.airbnb.lottie.LottieDrawable.draw(LottieDrawable.java:515)
```
It does not crash if renderMode is hardware.

Fixes #2026
  • Loading branch information
romankivalin committed Feb 28, 2022
1 parent d3d870b commit 9346684
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Expand Up @@ -1354,6 +1354,9 @@ private void drawDirectlyToCanvas(Canvas canvas) {
* @see LottieAnimationView#setRenderMode(RenderMode)
*/
private void renderAndDrawAsBitmap(Canvas originalCanvas, CompositionLayer compositionLayer) {
if (composition == null || compositionLayer == null) {
return;
}
ensureSoftwareRenderingObjectsInitialized();

//noinspection deprecation
Expand Down

0 comments on commit 9346684

Please sign in to comment.