Browse Source

fix: resolve bitmap recycling issue in long screenshot capture

- Create bitmap copy in ScreenCaptureService before passing to LongScreenshotCapture
- Handle null bitmap.config with fallback to ARGB_8888
- Add proper bitmap cleanup in processBitmapAsync with finally block
- Recycle bitmap copy in LongScreenshotCapture after processing
- Clean up bitmap copy if capture fails

This fixes the "Can't compress a recycled bitmap" error by ensuring
the bitmap passed to LongScreenshotCapture is not recycled by the
calling service before async processing completes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
feature/pgh-30-long-screenshot-capture
Dan 5 months ago
parent
commit
e25eadc566
  1. 11
      app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt
  2. 7
      app/src/main/java/com/quillstudios/pokegoalshelper/capture/LongScreenshotCapture.kt

11
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 {

7
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()
}
}
}

Loading…
Cancel
Save