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

Fix crash while using recycled bitmap in Session Replay #2396

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

ambushwork
Copy link
Member

What does this PR do?

A client reported SDK crash with stack trace:

Fatal Exception: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@cad0e02
       at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:83)
       at android.graphics.BaseCanvas.drawBitmap(BaseCanvas.java:174)
       at android.graphics.Canvas.drawBitmap(Canvas.java:1580)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:1008)
       at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:841)
       at com.datadog.android.sessionreplay.internal.recorder.wrappers.BitmapWrapper.createScaledBitmap$dd_sdk_android_session_replay_release(BitmapWrapper.java:46)
       at com.datadog.android.sessionreplay.internal.utils.DrawableUtils.createScaledBitmap$dd_sdk_android_session_replay_release(DrawableUtils.java:93)
       at com.datadog.android.sessionreplay.internal.utils.DrawableUtils.createScaledBitmap$dd_sdk_android_session_replay_release$default(DrawableUtils.java:84)
       at com.datadog.android.sessionreplay.internal.recorder.resources.ResourceResolver.tryToGetBitmapFromBitmapDrawable(ResourceResolver.java:231)
       at com.datadog.android.sessionreplay.internal.recorder.resources.ResourceResolver.createBitmap(ResourceResolver.java:112)
       at com.datadog.android.sessionreplay.internal.recorder.resources.ResourceResolver.resolveResourceId$lambda$0(ResourceResolver.java:76)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)

The reason is probably after checking the bitmap is not recycled, GC happened just before we really use the bitmap, so the it throws this RuntimeException.

The fix is that we catch the exception and return null, just ignore this bitmap instead of crashing the app.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@ambushwork ambushwork marked this pull request as ready for review November 15, 2024 14:07
@ambushwork ambushwork requested review from a team as code owners November 15, 2024 14:07
@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 69.74%. Comparing base (60631b4) to head (f9930d6).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
...replay/internal/recorder/wrappers/BitmapWrapper.kt 0.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2396      +/-   ##
===========================================
- Coverage    69.79%   69.74%   -0.05%     
===========================================
  Files          760      760              
  Lines        28310    28317       +7     
  Branches      4761     4761              
===========================================
- Hits         19757    19749       -8     
- Misses        7240     7250      +10     
- Partials      1313     1318       +5     
Files with missing lines Coverage Δ
...replay/internal/recorder/wrappers/BitmapWrapper.kt 7.41% <0.00%> (-2.59%) ⬇️

... and 30 files with indirect coverage changes

@ambushwork ambushwork merged commit c9b82d9 into develop Nov 15, 2024
24 checks passed
@ambushwork ambushwork deleted the yl/fix-sr-bitmap-crash branch November 15, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants