Skip to content

Commit

Permalink
win32: fix the issue of menu click failure caused by excessive menu-d…
Browse files Browse the repository at this point in the history
…ata updates

basically a copy of tsl0922/mpv-menu-plugin#77

if you have 200+ menu items and update `menu-data` about 400 times, click menu item 
does not execute any command, the reason is that the menu identifier greater than 
the max value of 16-bit unsigned integer.

as 861908c said, menu id must less than 0xF000.

1. make menu id always less than 0xF000.
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 authored Jan 17, 2025
1 parent ca211b5 commit 8b81729
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 greater than WM_USER and less than 0xF000
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 8b81729

Please sign in to comment.