Fix crash when using custom toolbar icons

Fix leak when using custom icons for toolbar.

Fix #16366, close #16367
This commit is contained in:
ozone10 2025-04-03 16:20:02 +02:00 committed by Don Ho
parent 5c1813185a
commit 07e8d84e04

View File

@ -92,14 +92,14 @@ void IconList::addIcon(HICON hIcon) const
ImageList_AddIcon(_hImglst, hIcon); ImageList_AddIcon(_hImglst, hIcon);
} }
bool IconList::changeIcon(size_t index, const wchar_t *iconLocation) const 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); HICON hIcon = nullptr;
if (!hBmp) DPIManagerV2::loadIcon(nullptr, iconLocation, _iconSize, _iconSize, &hIcon, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
if (!hIcon)
return false; return false;
size_t i = ImageList_ReplaceIcon(_hImglst, int(index), (HICON)hBmp); size_t i = ::ImageList_ReplaceIcon(_hImglst, static_cast<int>(index), hIcon);
ImageList_AddMasked(_hImglst, (HBITMAP)hBmp, RGB(255,0,255)); ::DestroyIcon(hIcon);
::DeleteObject(hBmp);
return (i == index); return (i == index);
} }
@ -107,7 +107,7 @@ void ToolBarIcons::init(ToolBarButtonUnit *buttonUnitArray, int arraySize, const
{ {
for (int i = 0 ; i < arraySize ; ++i) for (int i = 0 ; i < arraySize ; ++i)
_tbiis.push_back(buttonUnitArray[i]); _tbiis.push_back(buttonUnitArray[i]);
_moreCmds = moreCmds; _moreCmds = moreCmds;
} }