Ensure that menu item HBITMAPs live for long enough

We must keep storing the currently used bitmap in wxMSW wxMenuItem to
ensure that its HBITMAP remains valid, as keeping wxBitmapBundle is not
enough: it may not preserve the bitmap at all (if it generates it on
demand, for example), and we may also use a different bitmap from what
we get from it (e.g. we convert mask to alpha).
This commit is contained in:
Vadim Zeitlin
2022-02-05 20:31:18 +01:00
parent 28d8ed37d6
commit 99948ffc1d
2 changed files with 11 additions and 1 deletions

View File

@@ -1369,8 +1369,12 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind) const
#if wxUSE_IMAGE
if ( wxGetWinVersion() >= wxWinVersion_Vista )
{
// We need to store the returned bitmap, so that its HBITMAP remains
// valid for as long as it's used.
bool checked = (kind != Unchecked);
wxBitmap bmp = GetBitmap(checked);
wxBitmap& bmp = const_cast<wxBitmap&>(checked ? m_bmpCheckedCurrent
: m_bmpUncheckedCurrent);
bmp = GetBitmap(checked);
if ( bmp.IsOk() )
{
return GetHbitmapOf(bmp);