From 14aeeecd9c47578f95ea3ad500c2105825a4eeb0 Mon Sep 17 00:00:00 2001 From: cottongin Date: Wed, 18 Mar 2026 11:36:35 -0400 Subject: [PATCH] fix: guard zero-dimension bitmap and recycle on early return in BlurTransformation Made-with: Cursor --- .../cottongin/radio247/ui/util/BlurTransformation.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/xyz/cottongin/radio247/ui/util/BlurTransformation.kt b/app/src/main/java/xyz/cottongin/radio247/ui/util/BlurTransformation.kt index 85966a4..865584d 100644 --- a/app/src/main/java/xyz/cottongin/radio247/ui/util/BlurTransformation.kt +++ b/app/src/main/java/xyz/cottongin/radio247/ui/util/BlurTransformation.kt @@ -29,11 +29,15 @@ class BlurTransformation( private suspend fun Bitmap.stackBlur(scale: Float, radius: Int): Bitmap? = withContext(Dispatchers.IO) { var sentBitmap = this@stackBlur - val width = (sentBitmap.width * scale).roundToInt() - val height = (sentBitmap.height * scale).roundToInt() + val width = (sentBitmap.width * scale).roundToInt().coerceAtLeast(1) + val height = (sentBitmap.height * scale).roundToInt().coerceAtLeast(1) sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false) val bitmap = sentBitmap.copy(sentBitmap.config ?: Bitmap.Config.ARGB_8888, true) - if (radius < 1) return@withContext null + if (radius < 1) { + sentBitmap.recycle() + bitmap.recycle() + return@withContext null + } val w = bitmap.width val h = bitmap.height val pix = IntArray(w * h)