Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7b3f102 authored by George Mount's avatar George Mount
Browse files

Recover from bitmap decode failure.

 Skia errors out when decoding a bitmap into another bitmap
 sometimes. When this situation is detected, the decode is
 is retried without reusing a bitmap.

Change-Id: I935dec988ed7e115ceda9233a65d3b6083a17468
parent e0dbb510
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -97,13 +97,13 @@ public class BitmapDecoder {

    private static <T> Bitmap delegateDecode(Decoder<T> decoder, T input) {
        BitmapFactory.Options options = getOptions();
        GalleryBitmapPool pool = GalleryBitmapPool.getInstance();
        try {
            options.inJustDecodeBounds = true;
            if (!decoder.decodeBounds(input, options)) {
                return null;
            }
            options.inJustDecodeBounds = false;
            GalleryBitmapPool pool = GalleryBitmapPool.getInstance();
            Bitmap reuseBitmap = pool.get(options.outWidth, options.outHeight);
            options.inBitmap = reuseBitmap;
            Bitmap decodedBitmap = decoder.decode(input, options);
@@ -111,6 +111,13 @@ public class BitmapDecoder {
                pool.put(reuseBitmap);
            }
            return decodedBitmap;
        } catch (IllegalArgumentException e) {
            if (options.inBitmap == null) {
                throw e;
            }
            pool.put(options.inBitmap);
            options.inBitmap = null;
            return decoder.decode(input, options);
        } finally {
            options.inBitmap = null;
            options.inJustDecodeBounds = false;