0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

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
This commit is contained in:
der richter 2023-11-24 19:40:38 +01:00
parent 3f2bc2e535
commit cc09a28d96

View File

@ -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: