mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
4ffcf2531b
commit
e777756301
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue