Skip to content

Commit a122b06

Browse files
Neha Guptameta-codesync[bot]
authored andcommitted
Add isRecycled() check in DefaultDrawableFactory to prevent recycled bitmap crashes
Differential Revision: D101633098 fbshipit-source-id: 185ed105d7ffdb049503b6434d6efc723290a3fd
1 parent ea649f4 commit a122b06

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

‎drawee-backends/drawee-pipeline/src/main/java/com/facebook/drawee/backends/pipeline/DefaultDrawableFactory.java‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ public Drawable createDrawable(CloseableImage closeableImage) {
5757
if (closeableImage instanceof CloseableStaticBitmap) {
5858
CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage;
5959
Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
60-
if (bitmap == null) {
60+
if (bitmap == null || bitmap.isRecycled()) {
6161
return null;
6262
}
63-
Drawable bitmapDrawable = new BitmapDrawable(mResources, bitmap);
64-
if (!hasTransformableRotationAngle(closeableStaticBitmap)
65-
&& !hasTransformableExifOrientation(closeableStaticBitmap)) {
66-
// Return the bitmap drawable directly as there's nothing to transform in it
67-
return bitmapDrawable;
68-
} else {
69-
return new OrientedDrawable(
70-
bitmapDrawable,
71-
closeableStaticBitmap.getRotationAngle(),
72-
closeableStaticBitmap.getExifOrientation());
63+
try {
64+
Drawable bitmapDrawable = new BitmapDrawable(mResources, bitmap);
65+
if (!hasTransformableRotationAngle(closeableStaticBitmap)
66+
&& !hasTransformableExifOrientation(closeableStaticBitmap)) {
67+
return bitmapDrawable;
68+
} else {
69+
return new OrientedDrawable(
70+
bitmapDrawable,
71+
closeableStaticBitmap.getRotationAngle(),
72+
closeableStaticBitmap.getExifOrientation());
73+
}
74+
} catch (IllegalStateException e) {
75+
return null;
7376
}
7477
} else if (mAnimatedDrawableFactory != null
7578
&& mAnimatedDrawableFactory.supportsImageType(closeableImage)) {

0 commit comments

Comments
 (0)