Failed to load large image after 0.6.0
Hi All,
After upgrading the Fresco to version 0.7.0, I find that my app cannot display some images . It seems that it is caused by loading large image with down sample enabled. Following is the test code:
FLog.setMinimumLoggingLevel(FLog.VERBOSE);
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
.setDownsampleEnabled(true)
.build();
Fresco.initialize(getApplicationContext(), config);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSimpleDraweeView = (SimpleDraweeView)findViewById(R.id.image);
Uri imageUri = Uri.parse("file:///storage/emulated/0/image/pic2852.jpg");
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageUri)
.setResizeOptions(new ResizeOptions(158, 158))
.build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
.setOldController(mSimpleDraweeView.getController())
.setImageRequest(request)
.build();
mSimpleDraweeView.setController(controller);
With version 0.6.0, the image can be displayed correctly, and following is the log:
09-06 18:48:02.413 10024-10024/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41ea20d0 null -> 0: initialize 09-06 18:48:02.413 10024-10024/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41ea20d0 0: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@41e98970 09-06 18:48:02.440 10024-10024/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41ea20d0 0: onAttach: request needs submit 09-06 18:48:02.441 10024-10024/shawnone.com.frescotest V/unknown:PipelineDraweeController﹕ controller 41ea20d0: getDataSource 09-06 18:48:02.456 10024-10024/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41ea20d0 0: submitRequest: dataSource: 41eb6c78 09-06 18:48:02.493 10024-10039/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ Used = (1, 8192); Free = (0, 0) 09-06 18:48:02.516 10024-10040/shawnone.com.frescotest V/unknown:DownsampleUtil﹕ Downsample - Specified size: 158x158, image size: 8202x5456 ratio: 0.0 x 0.0, ratio: 0.029 for file:///storage/emulated/0/image/pic2852.jpg 09-06 18:48:02.520 10024-10038/shawnone.com.frescotest V/unknown:DownsampleUtil﹕ Downsample - Specified size: 158x158, image size: 8202x5456 ratio: 0.0 x 0.0, ratio: 0.029 for file:///storage/emulated/0/image/pic2852.jpg 09-06 18:48:02.522 10024-10038/shawnone.com.frescotest D/dalvikvm﹕ Trying to load lib /data/app-lib/shawnone.com.frescotest-1/libbitmaps.so 0x41e39590 09-06 18:48:02.525 10024-10038/shawnone.com.frescotest D/dalvikvm﹕ Added shared lib /data/app-lib/shawnone.com.frescotest-1/libbitmaps.so 0x41e39590 09-06 18:48:02.529 10024-10038/shawnone.com.frescotest D/skia﹕ jpeg_decoder mode 1, config 6, w 8202, h 5456, sample 32, bsLength 1150934!! 09-06 18:48:04.283 10024-10038/shawnone.com.frescotest D/skia﹕ jpeg_decoder finish successfully, L:1951!!! 09-06 18:48:04.294 10024-10024/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41ea20d0 0: set_final_result @ onNewResult: image: CloseableReference 41f12c10 09-06 18:48:04.308 10024-10024/shawnone.com.frescotest D/GraphicBuffer﹕ create handle(0x56427110) (w:480, h:800, f:1)
But with 0.7.0(0.6.1 also), the image failed to load:
09-06 18:43:44.995 8097-8097/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41eaa910 null -> 0: initialize 09-06 18:43:45.026 8097-8097/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41eaa910 0: onAttach: request needs submit 09-06 18:43:45.027 8097-8097/shawnone.com.frescotest V/unknown:PipelineDraweeController﹕ controller 41eaa910: getDataSource 09-06 18:43:45.036 8097-8097/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41eaa910 0: submitRequest: dataSource: 41ebee88 09-06 18:43:45.098 8097-8114/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ Used = (1, 8192); Free = (0, 0) 09-06 18:43:45.098 8097-8114/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ get (alloc) (object, size) = (41ecf8a0, 8192) 09-06 18:43:45.103 8097-8097/shawnone.com.frescotest D/GraphicBuffer﹕ create handle(0x54680f40) (w:480, h:800, f:1) 09-06 18:43:45.104 8097-8114/shawnone.com.frescotest D/skia﹕ jpeg_decoder mode 0, config 6, w 160, h 106, sample 1, bsLength 0!! 09-06 18:43:45.113 8097-8120/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ Used = (2, 18164020); Free = (0, 0) 09-06 18:43:45.113 8097-8120/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ get (alloc) (object, size) = (41ee48c0, 18155828) 09-06 18:43:45.113 8097-8120/shawnone.com.frescotest V/unknown:GenericByteArrayPool﹕ Used = (1, 16384); Free = (0, 0) 09-06 18:43:45.114 8097-8120/shawnone.com.frescotest V/unknown:GenericByteArrayPool﹕ get (alloc) (object, size) = (41ee50d0, 16384) 09-06 18:43:45.540 8097-8120/shawnone.com.frescotest V/unknown:GenericByteArrayPool﹕ release (reuse) (object, size) = (41ee50d0, 16384) 09-06 18:43:45.540 8097-8120/shawnone.com.frescotest V/unknown:GenericByteArrayPool﹕ Used = (0, 0); Free = (1, 16384) 09-06 18:43:45.544 8097-8120/shawnone.com.frescotest D/skia﹕ jpeg_decoder mode 0, config 6, w 8202, h 5456, sample 1, bsLength 0!! 09-06 18:43:45.562 8097-8123/shawnone.com.frescotest V/unknown:DownsampleUtil﹕ Downsample - Specified size: 158x158, image size: 8202x5456 ratio: 0.0 x 0.0, ratio: 0.029 for file:///storage/emulated/0/image/pic2852.jpg 09-06 18:43:45.563 8097-8123/shawnone.com.frescotest D/dalvikvm﹕ Trying to load lib /data/app-lib/shawnone.com.frescotest-2/libbitmaps.so 0x41e419e8 09-06 18:43:45.564 8097-8123/shawnone.com.frescotest D/dalvikvm﹕ Added shared lib /data/app-lib/shawnone.com.frescotest-2/libbitmaps.so 0x41e419e8 09-06 18:43:45.566 8097-8123/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ release (free) (object, size) = (41ee48c0, 18155828) 09-06 18:43:45.566 8097-8097/shawnone.com.frescotest V/unknown:AbstractDraweeController﹕ controller 41eaa910 0: final_failed @ onFailure: failure: com.facebook.imagepipeline.memory.BasePool$PoolSizeViolationException: Pool hard cap violation? Hard cap = 8388608 Used size = 0 Free size = 0 Request size = 18155830 09-06 18:43:45.573 8097-8123/shawnone.com.frescotest V/unknown:NativeMemoryChunkPool﹕ Used = (1, 8192); Free = (0, 0) 09-06 18:43:45.582 8097-8097/shawnone.com.frescotest D/GraphicBuffer﹕ create handle(0x5641b500) (w:480, h:800, f:1)
Any idea?
Thanks, Shawnone
Your logs indicate that your image is 18 MB before being resized. Resizing can handle that; downsampling can't right now. Since it is a jpeg I'd recommend turning off downsampling.
@tyronen So what's the max size the downsampling can handle now? I have tried to enable the downsampling in my app, it's really faster than resizing, but it's still not enabled by default, so what's your consideration for not enabling it.
The exact size will vary by device. We don't enable it by default yet because of this issue.
@tyronen Why has this limit? Yesterday after posting the comment, i found the downsampling is done by setting the BitmapFactory.Options.sample while decoding.
The limit is because, on Android 4.x and below, we load the entire encoded image into memory before decoding it. This is necessary in order to put the decoded image into ashmem. If the encoded images are small, this is not a problem, but you can run into memory problems on larger images and smaller devices.
Resizing avoids this by using C++ code to resize the encoded image in a separate, slower step before decoding it. So we have a speed vs memory safety tradeoff between downsampling and resizing.