summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa_cb_common.swift
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2021-03-26 02:32:49 -0500
committerrcombs <rcombs@rcombs.me>2022-09-14 16:28:12 -0500
commit588cb9a977c0ec4f278b827a67d7b46b84573057 (patch)
tree645034430c60673ce99d165de8ad1625e215cd62 /video/out/cocoa_cb_common.swift
parent750b58a5a37755972f3b34692eb9852354e8f077 (diff)
downloadmpv-588cb9a977c0ec4f278b827a67d7b46b84573057.tar.bz2
mpv-588cb9a977c0ec4f278b827a67d7b46b84573057.tar.xz
mac: avoid unnecessary unsafe conversions; fixes crash in debug builds
Previously, running a debug build of mpv would crash with this output when preinit() at vo_libmpv.c:732 calls control(vo, VOCTRL_PREINIT, NULL): Swift/Optional.swift:247: Fatal error: unsafelyUnwrapped of nil optional This comes from this line of code: var data = UnsafeMutableRawPointer.init(bitPattern: 0).unsafelyUnwrapped Unsafely unwrapping a UnsafeMutableRawPointer.init has always been UB, but the Swift runtime began asserting on it in debug builds a couple macOS versions ago.
Diffstat (limited to 'video/out/cocoa_cb_common.swift')
-rw-r--r--video/out/cocoa_cb_common.swift12
1 files changed, 2 insertions, 10 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift
index dd0738f7e3..5c312cbff0 100644
--- a/video/out/cocoa_cb_common.swift
+++ b/video/out/cocoa_cb_common.swift
@@ -167,17 +167,9 @@ class CocoaCB: Common {
layer?.update(force: true)
}
- var controlCallback: mp_render_cb_control_fn = { ( v, ctx, e, request, d ) -> Int32 in
+ var controlCallback: mp_render_cb_control_fn = { ( v, ctx, e, request, data ) -> Int32 in
let ccb = unsafeBitCast(ctx, to: CocoaCB.self)
- // the data pointer can be a null pointer, the libmpv control callback
- // provides nil instead of the 0 address like the usual control call of
- // an internal vo, workaround to create a null pointer instead of nil
- var data = UnsafeMutableRawPointer.init(bitPattern: 0).unsafelyUnwrapped
- if let dunwrapped = d {
- data = dunwrapped
- }
-
guard let vo = v, let events = e else {
ccb.log.sendWarning("Unexpected nil value in Control Callback")
return VO_FALSE
@@ -189,7 +181,7 @@ class CocoaCB: Common {
override func control(_ vo: UnsafeMutablePointer<vo>,
events: UnsafeMutablePointer<Int32>,
request: UInt32,
- data: UnsafeMutableRawPointer) -> Int32
+ data: UnsafeMutableRawPointer?) -> Int32
{
switch mp_voctrl(request) {
case VOCTRL_PREINIT: