Don't crash due to accessing invalid bitmaps in wxAUI code
Neither GetWidth() nor GetScaledWidth() (nor the corresponding height-related methods) can be called if the bitmap is invalid and the resulting assert led to a crash when it happened in wxAuiToolBarArt drawing code, as it was triggered on each redraw. Just use bitmap size of (0, 0) if we're not going to draw it anyhow. Closes #18263.
This commit is contained in:
parent
a316942c18
commit
c01328c2da
@ -293,15 +293,21 @@ void wxAuiGenericToolBarArt::DrawButton(
|
|||||||
int bmpX = 0, bmpY = 0;
|
int bmpX = 0, bmpY = 0;
|
||||||
int textX = 0, textY = 0;
|
int textX = 0, textY = 0;
|
||||||
|
|
||||||
|
const wxBitmap& bmp = item.GetState() & wxAUI_BUTTON_STATE_DISABLED
|
||||||
|
? item.GetDisabledBitmap()
|
||||||
|
: item.GetBitmap();
|
||||||
|
|
||||||
|
const wxSize bmpSize = bmp.IsOk() ? bmp.GetScaledSize() : wxSize(0, 0);
|
||||||
|
|
||||||
if (m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM)
|
if (m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM)
|
||||||
{
|
{
|
||||||
bmpX = rect.x +
|
bmpX = rect.x +
|
||||||
(rect.width/2) -
|
(rect.width/2) -
|
||||||
(item.GetBitmap().GetScaledWidth()/2);
|
(bmpSize.x/2);
|
||||||
|
|
||||||
bmpY = rect.y +
|
bmpY = rect.y +
|
||||||
((rect.height-textHeight)/2) -
|
((rect.height-textHeight)/2) -
|
||||||
(item.GetBitmap().GetScaledHeight()/2);
|
(bmpSize.y/2);
|
||||||
|
|
||||||
textX = rect.x + (rect.width/2) - (textWidth/2) + 1;
|
textX = rect.x + (rect.width/2) - (textWidth/2) + 1;
|
||||||
textY = rect.y + rect.height - textHeight - 1;
|
textY = rect.y + rect.height - textHeight - 1;
|
||||||
@ -312,9 +318,9 @@ void wxAuiGenericToolBarArt::DrawButton(
|
|||||||
|
|
||||||
bmpY = rect.y +
|
bmpY = rect.y +
|
||||||
(rect.height/2) -
|
(rect.height/2) -
|
||||||
(item.GetBitmap().GetScaledHeight()/2);
|
(bmpSize.y/2);
|
||||||
|
|
||||||
textX = bmpX + wnd->FromDIP(3) + item.GetBitmap().GetScaledWidth();
|
textX = bmpX + wnd->FromDIP(3) + bmpSize.x;
|
||||||
textY = rect.y +
|
textY = rect.y +
|
||||||
(rect.height/2) -
|
(rect.height/2) -
|
||||||
(textHeight/2);
|
(textHeight/2);
|
||||||
@ -351,12 +357,6 @@ void wxAuiGenericToolBarArt::DrawButton(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap bmp;
|
|
||||||
if (item.GetState() & wxAUI_BUTTON_STATE_DISABLED)
|
|
||||||
bmp = item.GetDisabledBitmap();
|
|
||||||
else
|
|
||||||
bmp = item.GetBitmap();
|
|
||||||
|
|
||||||
if ( bmp.IsOk() )
|
if ( bmp.IsOk() )
|
||||||
dc.DrawBitmap(bmp, bmpX, bmpY, true);
|
dc.DrawBitmap(bmp, bmpX, bmpY, true);
|
||||||
|
|
||||||
@ -596,8 +596,9 @@ wxSize wxAuiGenericToolBarArt::GetToolSize(
|
|||||||
if (!item.GetBitmap().IsOk() && !(m_flags & wxAUI_TB_TEXT))
|
if (!item.GetBitmap().IsOk() && !(m_flags & wxAUI_TB_TEXT))
|
||||||
return wnd->FromDIP(wxSize(16,16));
|
return wnd->FromDIP(wxSize(16,16));
|
||||||
|
|
||||||
int width = item.GetBitmap().GetScaledWidth();
|
const wxBitmap& bmp = item.GetBitmap();
|
||||||
int height = item.GetBitmap().GetScaledHeight();
|
int width = bmp.IsOk() ? bmp.GetScaledWidth() : 0;
|
||||||
|
int height = bmp.IsOk() ? bmp.GetScaledHeight() : 0;
|
||||||
|
|
||||||
if (m_flags & wxAUI_TB_TEXT)
|
if (m_flags & wxAUI_TB_TEXT)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user