diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index 2a768cd12f..e78522633f 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -125,6 +125,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap ) // Cannot add image to invalid list wxCHECK_MSG( m_size != wxSize(0, 0), -1, "Invalid image list" ); + const int index = GetImageCount(); const wxSize bitmapSize = bitmap.GetSize(); // There is a special case: a bitmap may contain more than one image, @@ -155,7 +156,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap ) return -1; } - return GetImageCount() - 1; + return index; } int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask ) diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp index 4e564ff91a..7823009dfc 100644 --- a/tests/graphics/imagelist.cpp +++ b/tests/graphics/imagelist.cpp @@ -569,6 +569,14 @@ TEST_CASE_METHOD(ImageListTestCase, CHECK(HasMaskOrAlpha(bmp2)); CHECK(bmp2.GetSize() == BITMAP_SIZE); } + + SECTION("Add 2x width image") + { + il.RemoveAll(); + int idx = il.Add(wxBitmap(BITMAP_SIZE.x * 2, BITMAP_SIZE.y)); + CHECK(idx == 0); + CHECK(il.GetImageCount() == 2); + } } TEST_CASE("ImageList:NegativeTests", "[imagelist][negative]")