Wordpress-android: Crash on many versions: RuntimeException: Canvas: trying to draw too large bitmap

Created on 20 Apr 2017  路  20Comments  路  Source: wordpress-mobile/WordPress-Android

https://www.fabric.io/automattic/android/apps/org.wordpress.android/issues/584116ea0aeb16625b8423b7

Seems possibly related to trying to display very large images. Added the "Media" label for that reason. Feel free to remove if not relevant.

Fatal Exception: java.lang.RuntimeException: Canvas: trying to draw too large(132986880bytes) bitmap.
       at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
       at android.graphics.Canvas.drawBitmap(Canvas.java:1420)
       at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
       at android.widget.ImageView.onDraw(ImageView.java:1286)
       at android.view.View.draw(View.java:18313)
       at android.view.View.updateDisplayListIfDirty(View.java:17291)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.draw(View.java:18316)
       at android.widget.ScrollView.draw(ScrollView.java:2774)
       at android.view.View.updateDisplayListIfDirty(View.java:17291)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.updateDisplayListIfDirty(View.java:17286)
       at android.view.View.draw(View.java:18075)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3966)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3752)
       at android.view.View.draw(View.java:18316)
       at com.android.internal.policy.DecorView.draw(DecorView.java:850)
       at android.view.View.updateDisplayListIfDirty(View.java:17291)
       at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:666)
       at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:672)
       at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:780)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:3093)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2889)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2483)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1490)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7027)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
       at android.view.Choreographer.doCallbacks(Choreographer.java:702)
       at android.view.Choreographer.doFrame(Choreographer.java:638)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6688)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
PostinEditing [Type] Crash

Most helpful comment

I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

I had the same problem. I didn't suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.

The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it's required size and trying to create a bitmap.

All 20 comments

Looking at the various logs, this appears to be an editor issue rather than a media one. I'm seeing a lot of instances of WordPress-EDITOR: Image tapped before the crash - perhaps the ImageSettingsDialogFragment is trying to load a full-sized image?

Yes, ImageSettingsDialogFragment was loading the full picture. Closing this for now since these kind of bugs has been fixed along the way in Media prj.

It's still happening in 7.6. From the log (filtering on 7.6 only) I see the Me activity as the last one tracked. Maybe it's a problem displaying the profile picture?

Dear developers,
I am analyzing WordPress using a static code checker. I find several code regions that loading full images from URL sites. Maybe one of them is the root cause of this bug. Maybe resize the image before displaying can fix this bug, and optimize all of them can avoid potential risks. Below are the details:
(1) https://github.com/wordpress-mobile/WordPress-Android/blob/develop/WordPress/src/main/java/org/wordpress/android/ui/posts/services/AztecImageLoader.java#L25

(2) https://github.com/wordpress-mobile/WordPress-Android/blob/develop/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/ImageUtils.java#L141

(3) https://github.com/wordpress-mobile/WordPress-Android/blob/develop/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/ImageSettingsDialogFragment.java#L365

Hope I can help improve WordPress.

I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

I had the same problem. I didn't suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.

The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it's required size and trying to create a bitmap.

@hypest did you solved the problem i am facing the same problem

Fatal Exception: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@6d43381
at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1271)
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:261)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528)
at android.widget.ImageView.onDraw(ImageView.java:1306)
at android.view.View.draw(View.java:17588)
at android.view.View.updateDisplayListIfDirty(View.java:16527)
at android.view.View.draw(View.java:17338)
....

馃憢 @mushtaq99 , I think Canvas: trying to use a recycled bitmap is most probably not related to the issue in this ticket.

30-day impact: ~7 per day
Users affected: 59 in the last 30d
Last seen in: 12.6

https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

90-day impact: ~6 per day
Users affected in the last 90 days: 161

https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

90-day impact: ~7 per day
Users affected in the last 90 days: 159

https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

From the log (filtering on 7.6 only) I see the Me activity as the last one tracked. Maybe it's a problem displaying the profile picture?

I checked logs today, filtering for 13.5, and in 8 out of 13 of them it looked like a problem trying to display very large images for updated posts in the Reader. @daniloercoli I could use a gut check on that interpretation though. 馃檪

Users affected in the last 90 days: 139
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

I tried these steps to trigger a crash:

  1. In the app, open the Reader stream for another site you're following where you can add a new post.
  2. On the web, go to the site and add a new post with a very large image.
  3. In the app, go to Reader and pull to refresh.

Result: no crash.

Can you suggest other testing scenarios to potentially try?

Users affected in the last 90 days: 154
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

So based on my investigation and reading several Glide issues especially this one, I think the devices are operating in an environment with memory constraints and they are crashing when attempting to load a large image in the Reader Photo View. Currently, we are using the device's viewport to calculate the image size that should be loaded and then passing the Photon URL generated from that size to Glide. To solve this we could

  1. lessen the image quality.
  2. Calculate the memory that will be needed to load the image and check the available memory and then utilize that value to determine the options that will be used to create the bitmap in a memory-efficient way.
  3. Put some logs in place to get the image file size and the app's available memory into Sentry.

I haven't been able to reproduce this as yet, but I will keep on doing so. let me know if anyone has any thoughts on this so I can know if I should attempt any of the ideas I have shared.

Users affected in the last 90 days: 164
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

An update. So I looked into this again. There's a crash I noticed that occurred because almost 15 images are present in a blog post and a user attempts to view them in the image preview. This causes 15 instances of the MediaPreviewFragment to be created and the app runs out of memory.

A solution for this case would be to limit the number of fragments that are loaded on-screen so that all instances don't have to be created especially because the user won't be viewing all the images at the same time.

10 events have been tracked for this crash in 14.6.1 since it was released 9d ago on Apr 22. [UPDATE: total events counted in 14.6.1 increased to 25 as of May 19.]

Number of users affected in the last 90d: 149
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

29 events have been tracked for this crash in 14.7 since it was released 15d ago on May 4.

Number of users affected in the last 90d: 126
Number of events in the last 90d: 1300
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

Events in the last 90d: 1300
Events in the last 9d since 14.8 was released: 21
Users affected in the last 90d: 123
Also see: 90d graph
https://sentry.io/share/issue/06479f2a38234c8abad668f173724b9f/

[UPDATE: added 90d graph.]

Screen Shot 2020-05-31 at May 31 10 18 20 PM

Was this page helpful?
0 / 5 - 0 ratings