Skip to content

[BUG] Crash when using custom toolbar icons #16366

@ozone10

Description

@ozone10

Is there an existing issue for this?

  • I have searched the existing issues

Description of the Issue

Function

bool IconList::changeIcon(size_t index, const wchar_t *iconLocation) const
{
HBITMAP hBmp = (HBITMAP)::LoadImage(_hInst, iconLocation, IMAGE_ICON, _iconSize, _iconSize, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
if (!hBmp)
return false;
size_t i = ImageList_ReplaceIcon(_hImglst, int(index), (HICON)hBmp);
ImageList_AddMasked(_hImglst, (HBITMAP)hBmp, RGB(255,0,255));
::DeleteObject(hBmp);
return (i == index);
}

is implemented wrong, HICON and HBITMAP are different types which cannot be interchanged. Casting one to other can cause undefined behavior. Icon should already support transparency so adding mask is not needed and can cause issue.

Steps To Reproduce

  1. Use custom icons
  2. In preference change toolbar icon set several times
  3. Observe visual glitch and eventually crash, this can be speed up by also switching between dark and light mode

Current Behavior

Potential visual glitches and crash.

Expected Behavior

No visual glitches and crash.

Debug Information

Notepad++ v8.7.9

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions