diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt index 88e0c46..c5eee66 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt +++ b/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt @@ -1328,13 +1328,18 @@ class ScreenCaptureService : Service() { val bitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888) Utils.matToBitmap(mat, bitmap) - // Pass the bitmap to the long screenshot system - val captured = longScreenshotCapture?.captureFrame(bitmap) ?: false + // Create a copy of the bitmap for long screenshot processing + val bitmapCopy = bitmap.copy(bitmap.config ?: Bitmap.Config.ARGB_8888, false) + + // Pass the bitmap copy to the long screenshot system + val captured = longScreenshotCapture?.captureFrame(bitmapCopy) ?: false if (!captured) { PGHLog.w(TAG, "⚠️ Failed to capture long screenshot frame") + // Clean up the copy if capture failed + bitmapCopy.recycle() } - // Clean up resources + // Clean up original resources bitmap.recycle() mat.release() } else { diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/capture/LongScreenshotCapture.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/capture/LongScreenshotCapture.kt index 8fda498..e52b878 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/capture/LongScreenshotCapture.kt +++ b/app/src/main/java/com/quillstudios/pokegoalshelper/capture/LongScreenshotCapture.kt @@ -321,6 +321,13 @@ class LongScreenshotCapture( PGHLog.e(TAG, "❌ Error processing bitmap", e) errorCallback?.invoke("Failed to save screenshot: ${e.message}") } + finally + { + // Always recycle the bitmap after processing + if (!bitmap.isRecycled) { + bitmap.recycle() + } + } }