Skip to content

Fix: prevent rare crash in GifDrawable.draw() when bitmap is null or … #5522

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yogeshkumawat
Copy link

What this fixes

This PR prevents a rare crash in GifDrawable.draw() when drawBitmap() is called on a null or recycled bitmap.

Why it matters

In large-scale production apps, this crash is observed occasionally (e.g., 100–200 times per 100k loads).
The crash happens because GifDrawable may try to draw a recycled or null bitmap during frame rendering.

Due to how Glide’s animation pipeline works internally, this crash cannot be caught by external Drawable or ImageView wrappers — Glide manages the Drawable.Callback lifecycle internally.

Fix

This PR adds a simple safety check inside GifDrawable.draw():

Bitmap currentFrame = state.frameLoader.getCurrentFrame();
if (currentFrame != null && !currentFrame.isRecycled()) {
  try {
    canvas.drawBitmap(currentFrame, null, getDestRect(), getPaint());
  } catch (Exception e) {
    Log.e("GifDrawable", "draw failed: " + e.getMessage());
  }
}

Copy link

google-cla bot commented May 28, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants