Skip to content

fix(windows): prevent use-after-free crash in Skia bitmap during dispose#199

Merged
kdroidFilter merged 1 commit intomasterfrom
fix/skia-bitmap-use-after-free
Apr 11, 2026
Merged

fix(windows): prevent use-after-free crash in Skia bitmap during dispose#199
kdroidFilter merged 1 commit intomasterfrom
fix/skia-bitmap-use-after-free

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

@kdroidFilter kdroidFilter commented Apr 11, 2026

Summary

  • Fix JVM crash (EXCEPTION_ACCESS_VIOLATION in skiko-windows-x64.dll) occurring when playback ends or the player is disposed
  • asComposeImageBitmap() is zero-copy — the resulting ImageBitmap shares native pixel memory with the source Bitmap. When dispose() called close() on the double-buffer bitmaps, Compose could still be rendering the last frame on the AWT-EventQueue thread, causing _nMakeFromBitmap to read freed memory
  • Instead of explicitly closing bitmaps, nullify references and let the Skia Managed cleaner free them once all holders (including Compose) drop their references — no memory leak, just ~50ms deferred cleanup

Test plan

  • Play a video to completion (non-loop mode) — no crash after "Playback ended"
  • Dispose the player mid-playback — no crash
  • Play multiple videos in sequence — no memory leak accumulation
  • Loop mode still works correctly

asComposeImageBitmap() shares native pixel memory with the source Bitmap.
When dispose() closed the double-buffer bitmaps, Compose could still be
rendering the last frame on the AWT-EventQueue thread, causing Skia's
_nMakeFromBitmap to read freed memory (EXCEPTION_ACCESS_VIOLATION in
skiko-windows-x64.dll).

Instead of calling close() explicitly, nullify references and let the
Skia Managed cleaner free them once all holders (including Compose)
drop their references.
@kdroidFilter kdroidFilter merged commit a76918c into master Apr 11, 2026
10 checks passed
@kdroidFilter kdroidFilter deleted the fix/skia-bitmap-use-after-free branch April 11, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant