Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory exception when loading large image #3181

Closed
mhdtouban opened this issue Jul 3, 2018 · 2 comments
Closed

Out of memory exception when loading large image #3181

mhdtouban opened this issue Jul 3, 2018 · 2 comments

Comments

@mhdtouban
Copy link

Trying to load image from gallery whith large size (3 mb or above) causing the crash.

4.7.1
works with okhttp3-1.4.0
fails on Galaxy S6 edge

trying to load image from gallery

Glide load line / `GlideModule:
GlideApp.with(this@GetMeAnythingActivity).load(imageUri)
.apply(RequestOptions.bitmapTransform(
RoundedCorners(Utils.dpToPxInt(this@GetMeAnythingActivity, 7F))))
.into(target)

private val target: BaseTarget<Drawable> = object : BaseTarget<Drawable>() {
    override fun onResourceReady(drawable: Drawable, transition: Transition<in Drawable>?) {
        val dp103 = Utils.dpToPxInt(this@GetMeAnythingActivity, 103F)
        imageView.layoutParams.height = dp103

        imageView.layoutParams.width = dp103
        imageView.requestLayout()

        linearLayout.background = null
        imageView.scaleType = ImageView.ScaleType.FIT_XY
        imageView.setImageDrawable(drawable)
        imageViewClear.visibility = View.VISIBLE
    }

    override fun getSize(cb: SizeReadyCallback) {
        cb.onSizeReady(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
    }

    override fun removeCallback(cb: SizeReadyCallback) {}
}

///

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

    if (resultCode == Activity.RESULT_OK)
        EasyImage.handleActivityResult(requestCode, resultCode, data, this, object : DefaultCallback() {
            override fun onImagePicked(imageFile: File?, source: EasyImage.ImageSource?, type: Int) {
                imageUri = Uri.fromFile(imageFile)
                loadImage(imageUri)
            }

            override fun onImagePickerError(e: Exception?, source: EasyImage.ImageSource?, type: Int) {
                Toast.makeText(this@GetMeAnythingActivity, e?.message, Toast.LENGTH_LONG).show()
            }
        })
}

**Stack trace / LogCat**:

W/Glide: Load failed for file:///data/user/0/com.ideatolife.butlr/cache/EasyImage/bcef9c92-49c5-4b0f-82b9-19d1271ac697.jpg with size [-2147483648x-2147483648]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 2 causes:
java.lang.OutOfMemoryError(Failed to allocate a 63489036 byte allocation with 16772320 free bytes and 47MB until OOM)
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException(Mark has been invalidated, pos: 53817 markLimit: 65536)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{FileInputStream->Object->Drawable}, LOCAL
There were 2 causes:
java.lang.OutOfMemoryError(Failed to allocate a 63489036 byte allocation with 16772320 free bytes and 47MB until OOM)
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException(Mark has been invalidated, pos: 53817 markLimit: 65536)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->Bitmap->Drawable}
There was 1 cause:
java.lang.OutOfMemoryError(Failed to allocate a 63489036 byte allocation with 16772320 free bytes and 47MB until OOM)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.lang.OutOfMemoryError: Failed to allocate a 63489036 byte allocation with 16772320 free bytes and 47MB until OOM
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->BitmapDrawable->Drawable}
There was 1 cause:
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException(Mark has been invalidated, pos: 53817 markLimit: 65536)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException: Mark has been invalidated, pos: 53817 markLimit: 65536
Cause (2 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptor->Object->Drawable}, LOCAL
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->Bitmap->Drawable}
Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->BitmapDrawable->Drawable}
Cause (3 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AssetFileDescriptor->Object->Drawable}, LOCAL
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AssetFileDescriptor->Bitmap->Drawable}
Cause (4 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{HierarchicalUri->Object->Drawable}, LOCAL
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Drawable->Drawable}
Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Bitmap->Drawable}
2018-07-03 18:15:42.750 13640-13640/com.ideatolife.butlr I/Glide: Root cause (1 of 2)
java.lang.OutOfMemoryError: Failed to allocate a 63489036 byte allocation with 16772320 free bytes and 47MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
at android.graphics.Bitmap.createBitmap(Bitmap.java:915)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.createBitmap(LruBitmapPool.java:149)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.get(LruBitmapPool.java:131)
at com.bumptech.glide.load.resource.bitmap.TransformationUtils.rotateImageExif(TransformationUtils.java:329)
at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeFromWrappedStreams(Downsampler.java:315)
at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:208)
at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:62)
at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:18)
at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:72)
at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:55)
at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:45)
at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:58)
at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:43)
at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:501)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:472)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:458)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:410)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:379)
at com.bumptech.glide.load.engine.SourceGenerator.onDataReady(SourceGenerator.java:112)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
2018-07-03 18:15:42.751 13640-13640/com.ideatolife.butlr I/Glide: Root cause (2 of 2)
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException: Mark has been invalidated, pos: 53817 markLimit: 65536
at com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream.reset(RecyclableBufferedInputStream.java:354)
at com.bumptech.glide.load.data.InputStreamRewinder.rewindAndGet(InputStreamRewinder.java:29)
at com.bumptech.glide.load.data.InputStreamRewinder.rewindAndGet(InputStreamRewinder.java:14)
at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:69)
at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:55)
at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:45)
at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:58)
at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:43)
at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:501)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:472)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:458)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:410)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:379)
at com.bumptech.glide.load.engine.SourceGenerator.onDataReady(SourceGenerator.java:112)
at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
2018-07-03 18:15:42.751 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: MSG_WINDOW_FOCUS_CHANGED 0
2018-07-03 18:15:42.753 13640-13640/com.ideatolife.butlr D/SEM_CLIP_SemClipboardManager: isCocktailBarDisplayed : false
2018-07-03 18:15:42.754 13640-13863/com.ideatolife.butlr V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 801
2018-07-03 18:15:42.756 13640-13863/com.ideatolife.butlr V/FA: Activity paused, time: 3120333526
2018-07-03 18:15:42.883 13640-13640/com.ideatolife.butlr D/InputTransport: Input channel destroyed: fd=128
2018-07-03 18:15:42.883 13640-13640/com.ideatolife.butlr W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
2018-07-03 18:15:42.884 13640-13640/com.ideatolife.butlr W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
2018-07-03 18:15:44.010 13640-13640/com.ideatolife.butlr W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
2018-07-03 18:15:44.011 13640-13640/com.ideatolife.butlr W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
2018-07-03 18:15:44.018 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: mHardwareRenderer.destroy()#1
2018-07-03 18:15:44.021 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: Relayout returned: oldFrame=[0,0][1080,1920] newFrame=[0,0][1080,1920] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true
2018-07-03 18:15:44.400 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: mHardwareRenderer.destroy()#1
2018-07-03 18:15:44.418 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: Relayout returned: oldFrame=[0,0][1080,1920] newFrame=[0,0][1080,1920] result=0x1 surface={isValid=false 0} surfaceGenerationChanged=false
2018-07-03 18:15:47.755 13640-13863/com.ideatolife.butlr V/FA: Inactivity, disconnecting from the service
2018-07-03 18:15:49.299 13640-15903/com.ideatolife.butlr D/skia: Encode PNG Singlethread : 16807693 us, width=2988, height=5312
2018-07-03 18:15:52.050 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: mHardwareRenderer.destroy()#1
2018-07-03 18:15:52.081 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: Relayout returned: oldFrame=[0,0][1080,1920] newFrame=[0,0][1080,1920] result=0x1 surface={isValid=false 0} surfaceGenerationChanged=false
2018-07-03 18:15:52.106 13640-13863/com.ideatolife.butlr V/FA: Connecting to remote service
2018-07-03 18:15:52.111 13640-13863/com.ideatolife.butlr V/FA: Activity resumed, time: 3120342875
2018-07-03 18:15:52.112 13640-13640/com.ideatolife.butlr W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
2018-07-03 18:15:52.128 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: Relayout returned: oldFrame=[0,0][1080,1920] newFrame=[0,0][1080,1920] result=0x7 surface={isValid=true 533007454208} surfaceGenerationChanged=true
2018-07-03 18:15:52.128 13640-13640/com.ideatolife.butlr D/ViewRootImpl@311d25[GetMeAnythingActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 533007454208} hwInitialized=true
2018-07-03 18:15:52.130 13640-13968/com.ideatolife.butlr D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1080x1920]-format:1
2018-07-03 18:15:52.156 13640-13640/com.ideatolife.butlr D/AndroidRuntime: Shutting down VM
2018-07-03 18:15:52.203 13640-13640/com.ideatolife.butlr E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ideatolife.butlr, PID: 13640
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@932de6d

@sjudd
Copy link
Collaborator

sjudd commented Jul 3, 2018

BaseTarget uses Target.SIZE_ORIGINAL. With sufficiently large images, that's a huge amount of memory. Use a ViewTarget, load into a View directly, or specify a reasonable size with override.

@stale
Copy link

stale bot commented Jul 10, 2018

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Jul 10, 2018
@stale stale bot closed this as completed Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants