fix(darwin): dispose crash

This commit is contained in:
edde746
2025-12-03 19:28:57 +01:00
parent a71354d9c5
commit d214ade2c6
2 changed files with 18 additions and 6 deletions
+10 -3
View File
@@ -428,9 +428,16 @@ class MpvPlayerCore: NSObject {
// MARK: - Cleanup
func dispose() {
if let mpv = mpv {
mpv_terminate_destroy(mpv)
self.mpv = nil
// Capture handle before clearing to avoid weak captures during deinit
let mpvHandle = mpv
mpv = nil
// Tear down on the mpv queue to avoid races with wakeup callbacks still firing
queue.sync {
if let handle = mpvHandle {
mpv_set_wakeup_callback(handle, nil, nil)
mpv_terminate_destroy(handle)
}
}
metalLayer?.removeFromSuperlayer()
metalLayer = nil