From 32dca39d92a3399b0f84c0c9af5222f1c43557b6 Mon Sep 17 00:00:00 2001 From: verygoodlee <45035465+verygoodlee@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:23:04 +0800 Subject: [PATCH] win32: fix menu click failure caused by excessive menu-data updates basically a copy of tsl0922/mpv-menu-plugin#77 if you have 200+ menu items and update `menu-data` about 400 times, clicking menu item will not execute any command, the reason is that the menu identifier greater than the max value of 16-bit unsigned integer. 1. make menu id always less than 0xF000 as mpv-player/mpv@861908c7 said 2. old menu items are never reused, should delete by DeleteMenu() instead of RemoveMenu(), destroys the handle and frees the memory --- video/out/win32/menu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/video/out/win32/menu.c b/video/out/win32/menu.c index 98891d32d6b93..d916a042e3bba 100644 --- a/video/out/win32/menu.c +++ b/video/out/win32/menu.c @@ -41,6 +41,8 @@ static int append_menu(HMENU hmenu, UINT fMask, UINT fType, UINT fState, mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | fMask; mii.wID = id++; + // menu id must be less than 0xF000 and greater than WM_USER + if (id >= 0xF000) id = WM_USER + 100; if (fMask & MIIM_FTYPE) mii.fType = fType; @@ -218,7 +220,7 @@ void mp_win32_menu_show(struct menu_ctx *ctx, HWND hwnd) void mp_win32_menu_update(struct menu_ctx *ctx, struct mpv_node *data) { while (GetMenuItemCount(ctx->menu) > 0) - RemoveMenu(ctx->menu, 0, MF_BYPOSITION); + DeleteMenu(ctx->menu, 0, MF_BYPOSITION); talloc_free_children(ctx->ta_data); build_menu(ctx->ta_data, ctx->menu, data);