Skip to content

[MEDIUM] [Android] Large images crashing the App - 'Canvas trying to draw too large' #34372

Description

@Julesssss

Problem

The Android app crashes due to a Canvas OOM exception when the image dimensions are extremely large. This has been fixed in the past, but we recently switched to Expo Image so I believe we'll need a new solution.

FATAL EXCEPTION: main
    Process: com.expensify.chat, PID: 28882
    java.lang.RuntimeException: Canvas: trying to draw too large(149730560bytes) bitmap.
    	at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
    	at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
    	at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
    	at android.widget.ImageView.onDraw(ImageView.java:1446)
    	at expo.modules.image.ExpoImageView.onDraw(ExpoImageView.kt:204)
    	at android.view.View.draw(View.java:23900)
    	at expo.modules.image.ExpoImageView.draw(ExpoImageView.kt:200)
    	at android.view.View.updateDisplayListIfDirty(View.java:22767)
    	at android.view.View.draw(View.java:23631)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:4559)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4320)
    	at android.view.View.updateDisplayListIfDirty(View.java:22758)
    	at android.view.View.draw(View.java:23631)
    	at android.view.ViewGroup.drawChild(ViewGroup.java:4559)
    	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4320)

We have spent time on different image libraries and many related issues, and I am now trying to combine our current issues and resolve the remaining canvas OOM exception.

  • Share a large image similar to this
  • Attempt to view the image as either a receipt upload or a regular image attachment

Solution

Collect all past attempts, recent merged PRs, and determine the best path forward for resolving the crash:

  • Here's where we merged Expo-Image
  • Here was a prior attempt to fix the image in react-native-fast-image
  • Another PR which attempted to fix the issue with an upstream react-native-fast-image PR
  • We introduced AttachmentGallary as an improvement to image scaling and a replacement to ImageZoom

Next question: Do we need a fix in Expo Image?

Activity

  1. changed the title [-][Android] Large images crashing the App -- Canvas trying to draw too large(149730560bytes)[/-] [+][Android] Large images crashing the App -- Canvas trying to draw too large[/+] on Jan 11, 2024
  2. self-assigned this
    on Jan 11, 2024
  3. deleted a comment from melvin-bot on Jan 11, 2024
  4. deleted a comment from melvin-bot on Jan 11, 2024
  5. Julesssss commented on Jan 11, 2024

    @Julesssss
    ContributorAuthor

    No C+ required yet

  6. changed the title [-][Android] Large images crashing the App -- Canvas trying to draw too large[/-] [+][Android] Large images crashing the App - Canvas trying to draw too large[/+] on Jan 11, 2024
  7. changed the title [-][Android] Large images crashing the App - Canvas trying to draw too large[/-] [+][Android] Large images crashing the App - 'Canvas trying to draw too large'[/+] on Jan 11, 2024
  8. moved this to Release 5: Best in Class in [#whatsnext] Wave 05 - Deprecate Freeon Jan 11, 2024
  9. 24 remaining items

  10. changed the title [-][Android] Large images crashing the App - 'Canvas trying to draw too large'[/-] [+][MEDIUM] [Android] Large images crashing the App - 'Canvas trying to draw too large'[/+] on Feb 20, 2024
  11. Julesssss commented on Feb 20, 2024

    @Julesssss
    ContributorAuthor

    Hey @chrispader, just wondering if you've heard anything else from Expo, or whether this conversation is taking place on a public GH repo?

  12. Julesssss commented on Feb 28, 2024

    @Julesssss
    ContributorAuthor

    Awaiting response from Expo and @chrispader

  13. Julesssss commented on Mar 13, 2024

    @Julesssss
    ContributorAuthor

    Asked for an update here

  14. Julesssss commented on Mar 20, 2024

    @Julesssss
    ContributorAuthor

    Fixed by #38671

  15. chrispader commented on Mar 20, 2024

    @chrispader
    Contributor

    Nice stuff! Sorry for not replying fast enough 🥲 I think this solution is valid, as long as expo-image takes care of the downsampling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EngineeringInternalRequires API changes or must be handled by Expensify staffSmartScanWave5-free-submittersWeeklyKSv2

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions