summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-06 00:34:49 +0200
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-05-07 10:52:39 +0900
commit9b41d17dc096169f14eb4d8eb4c4389caed64ee0 (patch)
tree17025128bd44fff88469cab1dc123ee8e4c535a3
parent5523c04af51a9e1c1975af501a71849baa2d4d40 (diff)
downloadmpv-9b41d17dc096169f14eb4d8eb4c4389caed64ee0.tar.bz2
mpv-9b41d17dc096169f14eb4d8eb4c4389caed64ee0.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. (cherry picked from commit e7777563018fc711c873ba9480744f0961786077)
-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);