glide icon indicating copy to clipboard operation
glide copied to clipboard

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

Open yogeshkumawat opened this issue 5 months ago • 1 comments

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());
  }
}

yogeshkumawat avatar May 28 '25 08:05 yogeshkumawat