Glide: Canvas Recycled Issue .

Created on 3 Aug 2018  路  3Comments  路  Source: bumptech/glide


Glide Version: 3.8.0


Integration libraries:


Device/Android Version: Not Specific but encounter on Vivo/ONEPLUS A5010 7.0/8.0


Issue details / Repro steps / Use case background:
java.lang.RuntimeException
Canvas: trying to use a recycled bitmap android.graphics.Bitmap@435f3b
com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable.draw


public class AppGlideManager implements GlideManager {

private Context context;
private Drawable mMalePlaceholderListing, mFemalePlaceholderListing;
private Drawable mMalePlaceholderProfileDetail, mFemalePlaceholderProfileDetail;

public AppGlideManager(Context context) {
    this.context = context;
}

@Override
public void preloadFallback() {
    Glide.with(context).load(getImageResource(LISTING, true)).listener(new RequestListener<Integer, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, Integer integer, Target<GlideDrawable> target, boolean b) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, Integer integer, Target<GlideDrawable> target, boolean b, boolean b1) {
            mFemalePlaceholderListing = resource;
            return false;
        }
    }).preload();
    Glide.with(context).load(getImageResource(LISTING, false)).listener(new RequestListener<Integer, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, Integer integer, Target<GlideDrawable> target, boolean b) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, Integer integer, Target<GlideDrawable> target, boolean b, boolean b1) {
            mMalePlaceholderListing = resource;
            return false;
        }
    }).preload();
    Glide.with(context).load(getImageResource(PROFILE_DETAIL, true)).listener(new RequestListener<Integer, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, Integer integer, Target<GlideDrawable> target, boolean b) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, Integer integer, Target<GlideDrawable> target, boolean b, boolean b1) {
            mFemalePlaceholderProfileDetail = resource;
            return false;
        }
    }).preload();
    Glide.with(context).load(getImageResource(PROFILE_DETAIL, false)).listener(new RequestListener<Integer, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, Integer integer, Target<GlideDrawable> target, boolean b) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, Integer integer, Target<GlideDrawable> target, boolean b, boolean b1) {
            mMalePlaceholderProfileDetail = resource;
            return false;
        }
    }).preload();
}}

This is just global factory for place holder I don't wish to reload with GlideRequest .
Please any better way around

question stale

All 3 comments

public class AppGlideManager implements GlideManager {

private Context context;
private Drawable mMalePlaceholderListing, mFemalePlaceholderListing;
private Drawable mMalePlaceholderProfileDetail, mFemalePlaceholderProfileDetail;

public AppGlideManager(Context context) {
    this.context = context;
}

@Override
public void preloadFallback() {
    Glide.with(context).load(getImageResource(LISTING, true)).asBitmap().dontAnimate().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
            mFemalePlaceholderListing = new BitmapDrawable(context.getResources(), bitmap.copy(bitmap.getConfig(), true));
            Glide.clear(this);
        }
    });
    Glide.with(context).load(getImageResource(LISTING, false)).asBitmap().dontAnimate().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
            mMalePlaceholderListing = new BitmapDrawable(context.getResources(), bitmap.copy(bitmap.getConfig(), true));
            Glide.clear(this);
        }
    });
    Glide.with(context).load(getImageResource(PROFILE_DETAIL, true)).asBitmap().dontAnimate().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
            mFemalePlaceholderProfileDetail = new BitmapDrawable(context.getResources(), bitmap.copy(bitmap.getConfig(), true));
            Glide.clear(this);
        }
    });
    Glide.with(context).load(getImageResource(PROFILE_DETAIL, false)).asBitmap().dontAnimate().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
            mMalePlaceholderProfileDetail = new BitmapDrawable(context.getResources(), bitmap.copy(bitmap.getConfig(), true));
            Glide.clear(this);
        }
    });
}}

Moved to this Approach hoped it will solve the problem .

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergeyfitis picture sergeyfitis  路  3Comments

Ncit picture Ncit  路  3Comments

piedpiperlol picture piedpiperlol  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

billy2271 picture billy2271  路  3Comments