Skip to content

Commit ae3dda4

Browse files
committed
Wrap into try-catch
1 parent 5dd2b60 commit ae3dda4

File tree

1 file changed

+37
-29
lines changed
  • sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot

1 file changed

+37
-29
lines changed

sentry-android-replay/src/main/java/io/sentry/android/replay/screenshot/CanvasStrategy.kt

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,41 +79,49 @@ internal class CanvasStrategy(
7979
}
8080
val picture = unprocessedPictureRef.getAndSet(null) ?: return@Runnable
8181

82-
// Draw picture to the Surface for PixelCopy
83-
val surfaceCanvas = surface.lockHardwareCanvas()
8482
try {
85-
surfaceCanvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR)
86-
picture.draw(surfaceCanvas)
87-
} finally {
88-
surface.unlockCanvasAndPost(surfaceCanvas)
89-
}
83+
// Draw picture to the Surface for PixelCopy
84+
val surfaceCanvas = surface.lockHardwareCanvas()
85+
try {
86+
surfaceCanvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR)
87+
picture.draw(surfaceCanvas)
88+
} finally {
89+
surface.unlockCanvasAndPost(surfaceCanvas)
90+
}
9091

91-
if (screenshot == null) {
92-
screenshotLock.acquire().use {
93-
if (screenshot == null) {
94-
screenshot = Bitmap.createBitmap(picture.width, picture.height, Bitmap.Config.ARGB_8888)
92+
if (screenshot == null) {
93+
screenshotLock.acquire().use {
94+
if (screenshot == null) {
95+
screenshot = Bitmap.createBitmap(picture.width, picture.height, Bitmap.Config.ARGB_8888)
96+
}
9597
}
9698
}
97-
}
9899

99-
// Trigger PixelCopy capture
100-
PixelCopy.request(
101-
surface,
102-
screenshot!!,
103-
{ result ->
104-
if (result == PixelCopy.SUCCESS) {
105-
lastCaptureSuccessful.set(true)
106-
val bitmap = screenshot
107-
if (bitmap != null && !bitmap.isRecycled) {
108-
screenshotRecorderCallback?.onScreenshotRecorded(bitmap)
100+
// Trigger PixelCopy capture
101+
PixelCopy.request(
102+
surface,
103+
screenshot!!,
104+
{ result ->
105+
if (result == PixelCopy.SUCCESS) {
106+
lastCaptureSuccessful.set(true)
107+
val bitmap = screenshot
108+
if (bitmap != null && !bitmap.isRecycled) {
109+
screenshotRecorderCallback?.onScreenshotRecorded(bitmap)
110+
}
111+
} else {
112+
options.logger.log(
113+
SentryLevel.ERROR,
114+
"Canvas Strategy: PixelCopy failed with code $result",
115+
)
116+
lastCaptureSuccessful.set(false)
109117
}
110-
} else {
111-
options.logger.log(SentryLevel.ERROR, "PixelCopy failed with code $result")
112-
lastCaptureSuccessful.set(false)
113-
}
114-
},
115-
executor.getBackgroundHandler(),
116-
)
118+
},
119+
executor.getBackgroundHandler(),
120+
)
121+
} catch (t: Throwable) {
122+
options.logger.log(SentryLevel.ERROR, "Canvas Strategy: picture render failed")
123+
lastCaptureSuccessful.set(false)
124+
}
117125
}
118126

119127
@SuppressLint("NewApi")

0 commit comments

Comments
 (0)