summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-06 00:34:49 +0200
committerwm4 <wm4@nowhere>2015-05-06 00:36:33 +0200
commite7777563018fc711c873ba9480744f0961786077 (patch)
tree0580f0532c6bfa7c344fd2c64c279e1ee895b54f /video
parent4ffcf2531bb525c19c3b6df75ecb27c5cffbdd28 (diff)
downloadmpv-e7777563018fc711c873ba9480744f0961786077.tar.bz2
mpv-e7777563018fc711c873ba9480744f0961786077.tar.xz
cocoa: lock cocoa main thread on uninit
This should fix some crashes due to dangling pointers. The problem was that with_cocoa_lock_on_main_thread() is asynchronous. It will not wait until it is finished. In the uninit case, this means the VO could be deallocated and destroyed while cocoa was still running uninit code. So simply wait until it is done by using dispatch_sync(). There were concerns that this could introduce a deadlock by the main thread trying to wait for something on the VO thread. But from what I can see, this never happens, and even if it does, it would crash anyway since the VO is already gone. One remaining worry is the video_resize_redraw_callback. From what I can see, it still can mess things up, and will need a more elaborate fix.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m10
1 files changed, 9 insertions, 1 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index e9c33d6f60..f9508d6719 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -107,6 +107,14 @@ static void with_cocoa_lock_on_main_thread(struct vo *vo, void(^block)(void))
});
}
+static void with_cocoa_lock_on_main_thread_sync(struct vo *vo, void(^block)(void))
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ with_cocoa_lock(s, block);
+ });
+}
+
static void queue_new_video_size(struct vo *vo, int w, int h)
{
struct vo_cocoa_state *s = vo->cocoa;
@@ -277,7 +285,7 @@ void vo_cocoa_uninit(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- with_cocoa_lock_on_main_thread(vo, ^{
+ with_cocoa_lock_on_main_thread_sync(vo, ^{
enable_power_management(s);
cocoa_uninit_light_sensor(s);
cocoa_rm_fs_screen_profile_observer(s);