From 882f0a46316f593980254db97ba9f1c39bbcec94 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 4 Apr 2021 21:00:05 +0200 Subject: [PATCH] Don't return a valid image from wxImageList if its index is out of range --- src/msw/imaglist.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index 373dacb088..9ee5283905 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -405,7 +405,9 @@ wxBitmap wxImageList::GetBitmap(int index) const if ( ii.hbmMask ) { // draw it the first time to find a suitable mask colour - const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT); + if ( !const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT) ) + return wxNullBitmap; + dc.SelectObject(wxNullBitmap); // find the suitable mask colour @@ -431,7 +433,9 @@ wxBitmap wxImageList::GetBitmap(int index) const else // no mask { // Just draw it normally. - const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL); + if ( !const_cast(this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL) ) + return wxNullBitmap; + dc.SelectObject(wxNullBitmap); // And adjust its alpha flag as the destination bitmap would get it if