Skip to content

Commit

Permalink
win32: fix menu click failure caused by excessive menu-data updates
Browse files Browse the repository at this point in the history
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 861908c7 said
2. old menu items are never reused, should delete by DeleteMenu()
   instead of RemoveMenu(), destroys the handle and frees the memory
  • Loading branch information
verygoodlee committed Jan 19, 2025
1 parent ca211b5 commit 32dca39
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion video/out/win32/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 32dca39

Please sign in to comment.