Skip to content

Commit a86e4c5

Browse files
committed
Refine bitmap cleanup in WindowsVideoPlayerState to avoid unintended disposal of shared frames.
1 parent 403e04e commit a86e4c5

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

mediaplayer/src/jvmMain/kotlin/io/github/kdroidfilter/composemediaplayer/windows/WindowsVideoPlayerState.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,14 @@ class WindowsVideoPlayerState : PlatformVideoPlayerState {
355355

356356
// Free bitmaps and frame buffers
357357
bitmapLock.write {
358-
_currentFrame?.close()
358+
val currentFrame = _currentFrame
359+
if (currentFrame != null &&
360+
currentFrame !== skiaBitmapA &&
361+
currentFrame !== skiaBitmapB &&
362+
currentFrame !== frameBitmapRecycler
363+
) {
364+
currentFrame.close()
365+
}
359366
_currentFrame = null
360367
currentFrameState.value = null
361368
frameBitmapRecycler?.close()
@@ -404,7 +411,14 @@ class WindowsVideoPlayerState : PlatformVideoPlayerState {
404411

405412
// Free bitmaps and frame buffers
406413
bitmapLock.write {
407-
_currentFrame?.close() // Close the current frame bitmap if any
414+
val currentFrame = _currentFrame
415+
if (currentFrame != null &&
416+
currentFrame !== skiaBitmapA &&
417+
currentFrame !== skiaBitmapB &&
418+
currentFrame !== frameBitmapRecycler
419+
) {
420+
currentFrame.close()
421+
}
408422
_currentFrame = null
409423
// Reset the currentFrameState
410424
currentFrameState.value = null
@@ -1284,4 +1298,4 @@ class WindowsVideoPlayerState : PlatformVideoPlayerState {
12841298
override fun toggleFullscreen() {
12851299
isFullscreen = !isFullscreen
12861300
}
1287-
}
1301+
}

0 commit comments

Comments
 (0)