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

Software rendering doesn't support hardware bitmaps #159

Closed
mt131 opened this issue Nov 1, 2019 · 26 comments
Closed

Software rendering doesn't support hardware bitmaps #159

mt131 opened this issue Nov 1, 2019 · 26 comments
Labels
bug Something isn't working

Comments

@mt131
Copy link

mt131 commented Nov 1, 2019

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:1516)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.widget.ImageView.onDraw(ImageView.java:1360)
at android.view.View.draw(View.java:20332)
at android.view.View.draw(View.java:20194)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1767)
at android.view.View.draw(View.java:20340)
at android.view.View.draw(View.java:20194)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5030)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20340)
at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
at android.view.View.draw(View.java:20194)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1767)
at android.view.View.draw(View.java:20340)
at android.view.View.draw(View.java:20194)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20192)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1767)
at android.view.View.draw(View.java:20340)
at android.view.View.draw(View.java:20194)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20192)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20192)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20192)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20192)
at android.view.ViewGroup.drawChild(ViewGroup.java:4395)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
at android.view.View.draw(View.java:20340)
at com.android.internal.policy.DecorView.draw(DecorView.java:781)
at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:3582)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3472)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3244)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2598)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1521)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7437)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:965)
at android.view.Choreographer.doCallbacks(Choreographer.java:777)
at android.view.Choreographer.doFrame(Choreographer.java:709)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)

@mt131 mt131 added the bug Something isn't working label Nov 1, 2019
@colinrtwhite
Copy link
Member

If you're rendering on a software only canvas, you'll need to add allowHardware(false) to your request.

@svenjacobs
Copy link

According to this information by Glide hardware bitmaps have a bug in Android Oreo (26) when used with shared element transitions that is fixed in Oreo 8.1.0 (27). Maybe hardware bitmaps should only be enabled by default for 27+?

@svenjacobs
Copy link

I also receive crashes for devices with Android 8.1. Will enable hardware bitmaps for Android 9+ only.

@colinrtwhite
Copy link
Member

@svenjacobs Hardware bitmaps are a pretty big optimization so I'd want to avoid disabling them. For the crashes, can you let me know if the devices you saw crashes for are in this list? There are a number of devices with hardware-specific issues that I'm working on blocking.

@mirland
Copy link

mirland commented Mar 9, 2020

I'm facing the same issue in two different devices that are not in the list
Devices:
One Plus 5: A5000 - Android 9
Pixel 2: walleye - Android 10

Code:

imageView.load(url)

url is a local image file, for example: file:///storage/emulated/0/DCIM/Camera/IMG_20200219_145106.jpg

The issue seems to be that i'm using a ShadowLayout as a parent of the image view

BTW: If I use allowHardware(false) the app works fine

@colinrtwhite
Copy link
Member

Hmm that's interesting. What's the stacktrace you're seeing?

@svenjacobs
Copy link

For the crashes, can you let me know if the devices you saw crashes for are in this list? There are a number of devices with hardware-specific issues that I'm working on blocking.

Here's a list of devices as reported by Firebase Crashlytics that crash with a "Software rendering doesn't support hardware bitmaps" during a shared element transition:

Android 8.1

A3
A60
Aquaris X
Aquaris X Pro
BlackBerry KEY2 LE
Blackview BV9500Pro
Cat S61
CUBOT_NOVA
CUBOT_POWER
Desire 12s
Galaxy J5
Galaxy J7 (2016)
Galaxy J7 Max
Galaxy J7 Prime
Galaxy Tab A (2016)
Gigaset GS270
Gigaset GS370
Gigaset GS370_Plus
GS280
K10
Lenovo TAB4 8 Plus
P1061X
Power 5
Redmi 5 Plus
Redmi Note 4
View2 Go
W_K400
Xperia XZ
ZenFone 4 Max (ZC520KL)

Android 8.0

Desire 12+
U Ultra
Xperia X Compact
Xperia XA1 Ultra
Xperia XZ

@mirland
Copy link

mirland commented Mar 10, 2020

Hmm that's interesting. What's the stacktrace you're seeing?

Stacktrace
    java.lang.IllegalArgumentException: Software rendering doesn't support hardware bitmaps
        at android.graphics.BaseCanvas.onHwBitmapInSwMode(BaseCanvas.java:632)
        at android.graphics.BaseCanvas.throwIfHwBitmapInSwMode(BaseCanvas.java:639)
        at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:73)
        at android.graphics.BaseCanvas.drawBitmap(BaseCanvas.java:131)
        at android.graphics.Canvas.drawBitmap(Canvas.java:1588)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:548)
        at android.widget.ImageView.onDraw(ImageView.java:1436)
        at android.view.View.draw(View.java:21975)
        at android.view.View.draw(View.java:21849)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.draw(View.java:21847)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.draw(View.java:21978)
        at android.view.View.draw(View.java:21849)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5030)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.draw(View.java:21978)
        at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
        at android.view.View.draw(View.java:21849)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.draw(View.java:21978)
        at android.view.View.draw(View.java:21849)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at com.gigamole.library.ShadowLayout.dispatchDraw(ShadowLayout.java:255)
        at android.view.View.draw(View.java:21978)
        at android.view.View.updateDisplayListIfDirty(View.java:20852)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1277)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.draw(View.java:21978)
        at android.view.View.updateDisplayListIfDirty(View.java:20852)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at androidx.fragment.app.FragmentContainerView.drawChild(FragmentContainerView.java:235)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at androidx.fragment.app.FragmentContainerView.dispatchDraw(FragmentContainerView.java:223)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1277)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4432)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4193)
        at android.view.View.updateDisplayListIfDirty(View.java:20843)
        at android.view.View.draw(View.java:21707)

I've been testing a bit more. My app has a rv with some images (a photo gallery) and the crash happens when I call notifyDataSetChanged().

@mirland
Copy link

mirland commented Mar 17, 2020

Hey @colinrtwhite I've tested it in the ShadowLayout library sample app and it's crashing, here is the example code, so you can try it.
I'm running basically this line:

  (findViewById<ImageView>(R.id.imageView))
        .load("https://github.com/xmartlabs/fountain/blob/master/images/banner.png?raw=true")

After a few seconds, the app crashes with the same issue.
I've used a Pixel 2 to test it

Maybe we can reopen the issue, what do you think?

@colinrtwhite
Copy link
Member

@matir91 Ah thanks for the sample code - sorry missed the last message. I believe this is working as intended as ShadowLayout doesn't seem to support hardware acceleration. Here it's substituting the backing bitmap for the canvas with a software ARGB_8888 bitmap. This turns the canvas into a software canvas which is unable to render hardware bitmaps. Removing that line should allow the view to draw hardware bitmaps, however I'm not sure if it will break the shadow effect. Unfortunately, there's no way to work around this other than setting allowHardware(false) for your request.

@mirland
Copy link

mirland commented Mar 17, 2020

Cool, thanks for explain me the cause of this issue! Yes, I can do it. I just wanted to be sure that this issue was not related to something wrong in this library. Thanks!

@damiancioo
Copy link

I recently had similar issue with 'Moto E5 play' during transitions, I see that on that list which @colinrtwhite shows it is, how should I know if I should enable allowHardware(false), HardwareBitmapService.kt has internal modifier, is there any better way than just copy it?

@colinrtwhite
Copy link
Member

The hardware bitmap blacklist maintains a list of devices that have issues with hardware bitmaps in all cases. Coil will automatically never use hardware bitmaps on those devices. You shouldn't need to copy the list externally. For shared element transitions, check out this recipe.

@ItzNotABug
Copy link

ItzNotABug commented Sep 19, 2020

I'm facing the same issue in two different devices that are not in the list
Devices:
One Plus 5: A5000 - Android 9
Pixel 2: walleye - Android 10

Code:

imageView.load(url)

url is a local image file, for example: file:///storage/emulated/0/DCIM/Camera/IMG_20200219_145106.jpg

The issue seems to be that i'm using a ShadowLayout as a parent of the image view

BTW: If I use allowHardware(false) the app works fine

Even I use ShadowLayout and got this same Crash,
However, below config seems to fix this :

thumbnail.load(File(path), imageLoader) {
    videoFrameMicros(2000)
    diskCachePolicy(CachePolicy.ENABLED)
    bitmapConfig(Bitmap.Config.ARGB_8888) // <-- specially this fixed my issue
}

@suleymanccelik
Copy link

suleymanccelik commented Dec 13, 2020

I am also facing the same issue in two different devices that are not in the list;
Xiaomi Redmi Plus 5 - Android 8.1
General Mobile GM8 Go - Android 8

I use neither shadowLayout nor shared element transition, I just use recyclerview with grid layout manager. Error occurs when the user switches between bottom navigation tabs quickly.

I use the coil library with following code snippet

fun ImageView.loadWithCoil(imageUrl: String?) {
    this.load(imageUrl) {
        crossfade(true)
        allowHardware(false)
        bitmapConfig(Bitmap.Config.ARGB_8888)
        placeholder(R.drawable.img_placeholder)
        error(R.drawable.img_placeholder)
        transformations(RoundedCornersTransformation(36F))
    }
}

Should I add another configuration line to solve the issue?

@Dailius
Copy link

Dailius commented Jan 22, 2022

I had the same issue with image load with coil in recyclerview adapter. Error occurs when user clicks on item from the recyclerview list to open new fragment to display item details. Solved in the same way and works fine:

imageView.load(ASSETS_DIR + item.imageBlackWhite){ 
                            allowHardware(false)
                            bitmapConfig(Bitmap.Config.ARGB_8888)
                        }

@alexanderdyndin
Copy link

alexanderdyndin commented May 16, 2022

I had same problem with shared elements but it appears randomly. for me helped this solution:
implement ImageLoaderFactory in your Application class:

class App : Application(), ImageLoaderFactory {
 ..........
 override fun newImageLoader(): ImageLoader {
         return ImageLoader.Builder(context)
                 .allowHardware(false)
                 .build()
     }
 } 

and just use singleton image loader

your_imageview.load(url) {
           ....
 }

idk why, but it works. Also i tried to create it inside dagger module and inject, but it didnt work.

@oguzhanaslann
Copy link

@suleymanccelik 's solution worked for me while working with coil library

@MohamedRejeb
Copy link
Contributor

MohamedRejeb commented Aug 26, 2022

I got the same error after using ShapeableImageView on Redmi 9s: Android 11
Setting bitmap config to ARGB_8888 was enough for me to fix the problem:
bitmapConfig(Bitmap.Config.ARGB_8888)

@mochadwi
Copy link

mochadwi commented Jul 14, 2023

The hardware bitmap blacklist maintains a list of devices that have issues with hardware bitmaps in all cases. Coil will automatically never use hardware bitmaps on those devices. You shouldn't need to copy the list externally. For shared element transitions, check out this recipe.

the crashed still occurred in Galaxy M12 android 13, our coil version is 2.2.0

https://github.com/coil-kt/coil/pull/308/files#diff-f2033b935fc07028e6e7fc5ae51ac1c0db814bc0426b118222382301a6886e42R107 (checked that galaxy is handled in here), am I missing something?

@lectricas
Copy link

So guys, which one is better?

bitmapConfig(Bitmap.Config.ARGB_8888)

or

allowHardware(false)

?

@pabvald3s
Copy link

Instead of applying allowHardware(false) unconditionally. Isn't a way to verify if the device support or not hardware bitmap. Applying allowHardware(false) will not take advantage of the hardware feature in the capable devices.
Canvas.isHardwareAccelerated() or View.isHardwareAccelerated() the same hardware feature we are talking about?

artwist-polyakov added a commit to artwist-polyakov/practicum-android-diploma that referenced this issue Dec 26, 2023
@radimjanda754
Copy link

@pabvald3s any update on this? Did you find some solution to not use allowHardware(false) when not necessary?

@pabvald3s
Copy link

@radimjanda754 Unfortunately not Sr.

@kuba14
Copy link

kuba14 commented Aug 23, 2024

I have tried basic compose example, as mentioned in their official docs. This issue appears. How can Coil team expect developers to use this code? If they wonder why someone uses concurrent libs, this is the case - basic simple example just do not work.

@vtabk2
Copy link

vtabk2 commented Oct 17, 2024

Why close ???

issue crash with io.coil-kt.coil3:coil:3.0.0-alpha01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests