Prevent NPE in ImageLayer.getBounds()#2578
Conversation
The recent [improvements to drop shadows](https://github.com/airbnb/lottie-android/pull/2548/files#diff-31e777f53a917d69dcf1b234ae6c77db843316c34911e200d0a9a160c058b621R110) added a dereference of a nullable result from the `getBitmap()` call.
|
Full stacktrace for reference: |
| } else { | ||
| outBounds.set(0, 0, getBitmap().getWidth() * scale, getBitmap().getHeight() * scale); | ||
| Bitmap bitmap = getBitmap(); | ||
| if (bitmap != null) { |
There was a problem hiding this comment.
What happens if this is null? Will outBounds potentially have a stale value from another frame?
There was a problem hiding this comment.
@gpeal I don't have the full context here so maybe @geomaster can chime in on what scenarios would cause the bitmap to be null and whether we need alternate behavior around updating outBounds.
There was a problem hiding this comment.
Unfortunately I'm not sure why the bitmap would be null - presumably, it has not loaded yet, or it didn't load correctly?
If the bitmap is null, we would be rendering nothing, so I think arguably the correct thing to do is simply to set to an empty rectangle, with outBounds.set(0, 0, 0, 0).
Thoughts?
There was a problem hiding this comment.
@geomaster @allenchen1154 do either of you want to take this across the finish line?
There was a problem hiding this comment.
@gpeal I've updated the else case as @geomaster recommended - PTAL.
The changes in airbnb#2578 set the bounds returned by `ImageLayer.getBounds()` to have 0 width and 0 height if there is no Bitmap available. This change instead calls the previous version of the logic which reads the width and height of the `LottieImageAsset`.
The changes in #2578 set the bounds returned by `ImageLayer.getBounds()` to have 0 width and 0 height if there is no Bitmap available. This change instead calls the previous version of the logic which reads the width and height of the `LottieImageAsset`.
The recent improvements to drop shadows added a dereference of a nullable result from the
getBitmap()call.Fixes #2601