-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent NPE in ImageLayer.getBounds() #2578
base: master
Are you sure you want to change the base?
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:
|
@@ -107,7 +107,10 @@ public class ImageLayer extends BaseLayer { | |||
if (lottieDrawable.getMaintainOriginalImageBounds()) { | |||
outBounds.set(0, 0, lottieImageAsset.getWidth() * scale, lottieImageAsset.getHeight() * scale); | |||
} else { | |||
outBounds.set(0, 0, getBitmap().getWidth() * scale, getBitmap().getHeight() * scale); | |||
Bitmap bitmap = getBitmap(); | |||
if (bitmap != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this is null? Will outBounds potentially have a stale value from another frame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
The recent improvements to drop shadows added a dereference of a nullable result from the
getBitmap()
call.