From ee2e14015d1b8cfcb832ad08cf02177fe91d064e Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:49:54 -0400 Subject: [PATCH] win32: move context menu init/uninit to GUI thread Currently if VO init fails, the context menu is leaked. Additionally, init/uninit are in the VO thread, while other accesses are in the GUI thread. Fix this by moving them to the GUI thread, similar to other resources. This also lets init function take the mpv HWND in the next commit. --- video/out/w32_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index d30c7ccb1f..4015a199f7 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -2031,6 +2031,7 @@ static MP_THREAD_VOID gui_thread(void *ptr) goto done; } + w32->menu_ctx = mp_win32_menu_init(); update_dark_mode(w32); update_corners_pref(w32); if (w32->opts->window_affinity) @@ -2106,6 +2107,8 @@ done: MP_VERBOSE(w32, "uninit\n"); remove_parent_hook(w32); + if (w32->menu_ctx) + mp_win32_menu_uninit(w32->menu_ctx); if (w32->window && !w32->destroyed) DestroyWindow(w32->window); if (w32->taskbar_list) @@ -2131,7 +2134,6 @@ bool vo_w32_init(struct vo *vo) .dispatch = mp_dispatch_create(w32), }; w32->opts = w32->opts_cache->opts; - w32->menu_ctx = mp_win32_menu_init(); vo->w32 = w32; if (mp_thread_create(&w32->thread, gui_thread, w32)) @@ -2422,7 +2424,6 @@ void vo_w32_uninit(struct vo *vo) AvRevertMmThreadCharacteristics(w32->avrt_handle); - mp_win32_menu_uninit(w32->menu_ctx); talloc_free(w32); vo->w32 = NULL; }