Lottie-android: recycleBitmaps throw NullPointerException while onDestroy after LottieAnimationView updateBitmap with a null bitmap

Created on 9 Jan 2018  路  7Comments  路  Source: airbnb/lottie-android

LottieAnimationView throws NullPointerException while activity onDestoy. Because a bitmap in ImageAssetManager bitmaps is null. I call LottieAnimationView updateBitmap(id, null) because I need clear the bitmap, after this the exception would occur while onDestroy.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference at com.airbnb.lottie.manager.ImageAssetManager.recycleBitmaps(ImageAssetManager.java:96) at com.airbnb.lottie.LottieDrawable.recycleBitmaps(LottieDrawable.java:142) at com.airbnb.lottie.LottieAnimationView.recycleBitmaps(LottieAnimationView.java:277) at com.airbnb.lottie.LottieAnimationView.onDetachedFromWindow(LottieAnimationView.java:269) at android.view.View.dispatchDetachedFromWindow(View.java:15668) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3183) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3183) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4719) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4693) at android.view.ViewGroup.removeView(ViewGroup.java:4624) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1205) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268) at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:2180) at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:271) at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:386) at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:202)

Most helpful comment

public void recycleBitmaps() {
 Iterator<Map.Entry<String, Bitmap>> it = bitmaps.entrySet().iterator(); 
while (it.hasNext()) {
try {
 Map.Entry<String, Bitmap> entry = it.next();
 entry.getValue().recycle(); //
 if (entry.getValue() != null) 
it.remove(); 
 break;
    } catch (MyException ex) {
      log.warn("Something failed.", ex);
    }
 }
}

All 7 comments

btmp is null. There is no way that by using the attached code.Then, the value of btmp would be anything. But it's null!

If you want to clone Bitmap the use create method or any other of that sort.

Bitmap btmp = Bitmap.create(drawable.getBitmap());

public void recycleBitmaps() { Iterator<Map.Entry<String, Bitmap>> it = bitmaps.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Bitmap> entry = it.next(); entry.getValue().recycle(); // if (entry.getValue() != null) it.remove(); } }
I think the method of ImageAssetManager should check the bitmap is null or not, because the bitmap may be null after call LottieAnimationView.updateBitmap(String id, @Nullable Bitmap bitmap).

public void recycleBitmaps() {
 Iterator<Map.Entry<String, Bitmap>> it = bitmaps.entrySet().iterator(); 
while (it.hasNext()) {
try {
 Map.Entry<String, Bitmap> entry = it.next();
 entry.getValue().recycle(); //
 if (entry.getValue() != null) 
it.remove(); 
 break;
    } catch (MyException ex) {
      log.warn("Something failed.", ex);
    }
 }
}

@gpeal i use 'com.airbnb.android:lottie:2.6.0-beta19',and it reproduce

where do I call the recycleBitmaps() method?

public void recycleBitmaps() {
 Iterator<Map.Entry<String, Bitmap>> it = bitmaps.entrySet().iterator(); 
while (it.hasNext()) {
try {
 Map.Entry<String, Bitmap> entry = it.next();
 entry.getValue().recycle(); //
 if (entry.getValue() != null) 
it.remove(); 
 break;
    } catch (MyException ex) {
      log.warn("Something failed.", ex);
    }
 }
}

Getting same issue.

@usmanrana07 This will be resolved with #1002

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lawloretienne picture lawloretienne  路  5Comments

SwayChen picture SwayChen  路  5Comments

hkchakladar picture hkchakladar  路  3Comments

AndroidDeveloperLB picture AndroidDeveloperLB  路  4Comments

Anmolk22 picture Anmolk22  路  3Comments