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

Crash when loading image into AppCompatImageView #31

Closed
overpas opened this issue Aug 15, 2019 · 6 comments · Fixed by #40
Closed

Crash when loading image into AppCompatImageView #31

overpas opened this issue Aug 15, 2019 · 6 comments · Fixed by #40
Labels
needs info Further information is requested

Comments

@overpas
Copy link

overpas commented Aug 15, 2019

I attempted to migrate from Glide to Coil in my app. After switching to Coil, the app crashed in runtime as soon as an image was downloaded when it was being set to a androidx.appcompat.widget.AppCompatImageView descendant.
May be worth to note, that I'm using this ui library: https://github.com/stfalcon-studio/ChatKit
Could you help me understand what the issue is and if there are any possible workarounds?

Here's the stacktrace:
java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps at android.graphics.BaseCanvas.onHwBitmapInSwMode(BaseCanvas.java:550) at android.graphics.BaseCanvas.throwIfHwBitmapInSwMode(BaseCanvas.java:557) at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:69) at android.graphics.BaseCanvas.drawBitmap(BaseCanvas.java:127) at android.graphics.Canvas.drawBitmap(Canvas.java:1504) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545) at android.widget.ImageView.onDraw(ImageView.java:1360) at com.stfalcon.chatkit.utils.ShapeImageView.onDraw(ShapeImageView.java:70) at android.view.View.draw(View.java:20207) at android.view.View.buildDrawingCacheImpl(View.java:19478) at android.view.View.buildDrawingCache(View.java:19338) at android.view.View.draw(View.java:19927) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.updateDisplayListIfDirty(View.java:19073) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5011) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.draw(View.java:20210) at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4410) at android.view.View.updateDisplayListIfDirty(View.java:19082) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.draw(View.java:20210) at android.view.View.updateDisplayListIfDirty(View.java:19082) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.draw(View.java:20210) at android.view.View.updateDisplayListIfDirty(View.java:19082) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.updateDisplayListIfDirty(View.java:19073) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.updateDisplayListIfDirty(View.java:19073) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.updateDisplayListIfDirty(View.java:19073) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.updateDisplayListIfDirty(View.java:19073) at android.view.View.draw(View.java:19935) at android.view.ViewGroup.drawChild(ViewGroup.java:4333) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4112) at android.view.View.draw(View.java:20210) at com.android.internal.policy.DecorView.draw(DecorView.java:780) at android.view.View.updateDisplayListIfDirty(View.java:19082) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:801) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3311) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3115) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2484) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:696) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@colinrtwhite
Copy link
Member

Do you have View.LAYER_TYPE_SOFTWARE set on your ImageView or do you know if the library enables software rendering behind the scenes? Either way you should be able to fix this by using:

imageView.load(url) {
    allowHardware(false)
}

This prevents using hardware Bitmaps for that request.

@colinrtwhite colinrtwhite added the needs info Further information is requested label Aug 15, 2019
@overpas
Copy link
Author

overpas commented Aug 16, 2019

Thanks, the ImageView has View.LAYER_TYPE_SOFTWARE set on it, and indeed allowHardware(false) fixes the thing.
Is there a way to apply allowHardware(false) on each LoadRequest by default globally?

@colinrtwhite
Copy link
Member

@overpas Can you describe your use case for disabling hardware Bitmaps globally? Currently, there's no way to do this, as it's bad for performance to globally disable hardware Bitmaps.

@overpas
Copy link
Author

overpas commented Aug 16, 2019

In my use case I can disable the flag View.LAYER_TYPE_SOFTWARE on views, but maybe if some 3d-party library that requires the View.LAYER_TYPE_SOFTWARE flag is used throughout the code, then there should be a possibility to globally apply allowHardware(false) when images are loaded

@colinrtwhite
Copy link
Member

Fair enough. You should avoid enabling allowHardware(false) in most cases, but there could be instances where you want to disable it entirely for an ImageLoader. I created #40 to implement this.

@janbarari
Copy link

I fixed this issue by adding allowHardware(false) in my coil configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants