summaryrefslogtreecommitdiffstats
path: root/video/out/mac/common.swift
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2023-11-24 19:40:38 +0100
committerder richter <der.richter@gmx.de>2023-11-25 19:31:26 +0100
commitcc09a28d96387fd8337fedb3fa0e7b613ce74d40 (patch)
treef9a37cab62e8fd9aad41625e4e3491fe8adbebe3 /video/out/mac/common.swift
parent3f2bc2e5355e7588585de3f74b224947e89ce256 (diff)
downloadmpv-cc09a28d96387fd8337fedb3fa0e7b613ce74d40.tar.bz2
mpv-cc09a28d96387fd8337fedb3fa0e7b613ce74d40.tar.xz
mac: fix a race condition when updating the window title
the title is updated on the main thread (mandatory with cocoa) asynchronously, because otherwise it would either deadlock when done synchronously, lead to undefined behaviour or just crashes. the problem here is that the c string was only copied to an NSString within that asynchronous call, which potentially would access the pointer when it is accessed, modified or freed by another thread. it is only safe to access this pointer as long as the control callback wasn't returned yet. to fix this we move the copying and creation of the String from the c string pointer outside of the asynchronous call where the conversion of an untyped pointer to a typed pointer is done too. since the resulting String is a copy it's safe to be used in the asynchronous call. also reverting ee6ad40, since the problem was most likely an SDK problem or the very same problem as mentioned here. i retested the crash case again und can't reproduce it anymore. using a swift String again instead of an NSSstring. Fixes #12935
Diffstat (limited to 'video/out/mac/common.swift')
-rw-r--r--video/out/mac/common.swift5
1 files changed, 2 insertions, 3 deletions
diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift
index aac705005f..3c01abe572 100644
--- a/video/out/mac/common.swift
+++ b/video/out/mac/common.swift
@@ -650,10 +650,9 @@ class Common: NSObject {
focus.pointee = NSApp.isActive
return VO_TRUE
case VOCTRL_UPDATE_WINDOW_TITLE:
- let titleData = data!.assumingMemoryBound(to: Int8.self)
+ let title = String(cString: data!.assumingMemoryBound(to: CChar.self))
DispatchQueue.main.async {
- let title = NSString(utf8String: titleData) as String?
- self.title = title ?? "Unknown Title"
+ self.title = title
}
return VO_TRUE
default: