summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-02-16 23:54:52 +0100
committerder richter <der.richter@gmx.de>2024-02-18 17:25:05 +0100
commitac275a823d9c86168dd7ee39bcc7e3aa1b4830dc (patch)
treeaf3080a891c02ca7b2683a667b84e04b5b3c387c
parent3fd840f85dc52da99feee0c682e22f5867f8c8cb (diff)
downloadmpv-ac275a823d9c86168dd7ee39bcc7e3aa1b4830dc.tar.bz2
mpv-ac275a823d9c86168dd7ee39bcc7e3aa1b4830dc.tar.xz
cocoa-cb: lock CGLContext on uninit and manual redraw
this fixes a crash on quit, when a CATransaction from a system owned thread/event is happening at the same time. locking the context synchronises these access and prevents the race condition. the draw operation induced by any display call from the CAOpenGLLayer doesn't need that lock, since the display function already does lock that current context. Fixes #11681
-rw-r--r--video/out/cocoa_cb_common.swift2
-rw-r--r--video/out/mac/gl_layer.swift10
2 files changed, 12 insertions, 0 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift
index 4655cabf9b..094dab1a55 100644
--- a/video/out/cocoa_cb_common.swift
+++ b/video/out/cocoa_cb_common.swift
@@ -209,7 +209,9 @@ class CocoaCB: Common {
uninit()
uninitCommon()
+ layer?.lockCglContext()
libmpv.deinitRender()
+ layer?.unlockCglContext()
libmpv.deinitMPV(destroy)
}
diff --git a/video/out/mac/gl_layer.swift b/video/out/mac/gl_layer.swift
index dd96af7265..d0d3a6de16 100644
--- a/video/out/mac/gl_layer.swift
+++ b/video/out/mac/gl_layer.swift
@@ -199,6 +199,14 @@ class GLLayer: CAOpenGLLayer {
}
}
+ func lockCglContext() {
+ CGLLockContext(cglContext)
+ }
+
+ func unlockCglContext() {
+ CGLUnlockContext(cglContext)
+ }
+
override func copyCGLPixelFormat(forDisplayMask mask: UInt32) -> CGLPixelFormatObj {
return cglPixelFormat
}
@@ -219,10 +227,12 @@ class GLLayer: CAOpenGLLayer {
super.display()
CATransaction.flush()
if isUpdate && needsFlip {
+ lockCglContext()
CGLSetCurrentContext(cglContext)
if libmpv.isRenderUpdateFrame() {
libmpv.drawRender(NSZeroSize, bufferDepth, cglContext, skip: true)
}
+ unlockCglContext()
}
displayLock.unlock()
}