fresco icon indicating copy to clipboard operation
fresco copied to clipboard

ShapeDrawable mutation not working on Android 4.1.2

Open emhagman opened this issue 11 years ago • 8 comments

java.lang.NullPointerException
       at android.graphics.Rect.<init>(Rect.java:72)
       at android.graphics.drawable.ShapeDrawable.mutate(ShapeDrawable.java:377)
       at com.facebook.drawee.drawable.ForwardingDrawable.mutate(ForwardingDrawable.java:160)
       at com.facebook.drawee.drawable.FadeDrawable.drawDrawableWithAlpha(FadeDrawable.java:304)
       at com.facebook.drawee.drawable.FadeDrawable.draw(FadeDrawable.java:293)
       at com.facebook.drawee.drawable.ForwardingDrawable.draw(ForwardingDrawable.java:140)
       at com.facebook.drawee.generic.GenericDraweeHierarchy$RootDrawable.draw(GenericDraweeHierarchy.java:133)
       at android.widget.ImageView.onDraw(ImageView.java:984)

Any ideas what could be causing this? Only seems to be happening specifically on Android version 4.1.2, both on Samsung devices.

emhagman avatar Jul 28 '15 15:07 emhagman

There seems to be a bug in 4.1.2: ShapeDrawable.mutate copies its padding Rect without checking whether it is null anywhere. Calling setPadding(new Rect()) before calling mutate should help work around this issue. Marking this as a bug until some work around is in place.

michalgr avatar Jul 29 '15 11:07 michalgr

Thank you for the quick response! Is there anything I can do in the meantime to mitigate the issue on my side?

emhagman avatar Jul 29 '15 17:07 emhagman

You can try setting padding on the shape drawable in your app. Let me know if that helps.

michalgr avatar Jul 30 '15 10:07 michalgr

So why didn't you fix this? Why didn't you accept pull request from emhagman?

D00mch avatar Apr 05 '17 13:04 D00mch

I fixed the problem by adding drawable.setPadding(new Rect()) to the drawable, that I used in

GenericDraweeHierarchyBuilder(getResources())
      .setFailureImage(drawable);

D00mch avatar Apr 05 '17 16:04 D00mch

@Liverm0r, the PR was taken back by @emhagman one hour after he opened it. Let me try to find some time this week to look into it

lambdapioneer avatar Apr 10 '17 09:04 lambdapioneer

I am facing same issue for setPlaceholderImage. any workaround?

PalDhv avatar Jan 02 '18 13:01 PalDhv

Closing since we will not be fixing this (due to Android 4.1.2 being quite obsolete at this point)

erikandre avatar Jul 12 '18 14:07 erikandre