Skip to content

Commit 31434da

Browse files
committed
nullable createBitmapForView
1 parent bc806a6 commit 31434da

File tree

1 file changed

+12
-2
lines changed
  • sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/capture

1 file changed

+12
-2
lines changed

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/capture/CaptureSource.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class CaptureSource(
200200
view: View,
201201
rect: Rect,
202202
): Bitmap? {
203-
val bitmap = createBitmap(view.width, view.height)
203+
val bitmap = createBitmapForView(view) ?: return null
204204

205205
return suspendCancellableCoroutine { continuation ->
206206
val handler = Handler(Looper.getMainLooper())
@@ -229,7 +229,7 @@ class CaptureSource(
229229
private fun canvasDraw(
230230
view: View
231231
): Bitmap? {
232-
val bitmap = createBitmap(view.width, view.height)
232+
val bitmap = createBitmapForView(view) ?: return null
233233

234234
val canvas = Canvas(bitmap)
235235
try {
@@ -242,6 +242,16 @@ class CaptureSource(
242242
return bitmap
243243
}
244244

245+
private fun createBitmapForView(view: View): Bitmap? {
246+
val width = view.width
247+
val height = view.height
248+
if (width <= 0 || height <= 0) {
249+
logger.warn("Cannot draw view with zero dimensions: ${view.width}x${view.height}")
250+
return null
251+
}
252+
return createBitmap(width, height)
253+
}
254+
245255
private fun createCaptureEvent(
246256
postMask: Bitmap,
247257
rect: Rect,

0 commit comments

Comments
 (0)