diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 0f83b4da24..3316c0b14e 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -803,12 +803,18 @@ size_t wxBitmapBundleImpl::GetIndexToUpscale(const wxSize& size) const size_t indexLast = 0; const wxSize sizeDef = GetDefaultSize(); - for ( size_t i = 0;; indexLast = i) + for ( size_t i = 0;; ) { + // Save it before it's updated by GetNextAvailableScale(). + size_t indexPrev = i; + const double scaleThis = GetNextAvailableScale(i); if ( scaleThis == 0.0 ) break; + // Only update it now, knowing that this index could have been used. + indexLast = indexPrev; + const double scale = size.y / (sizeDef.y*scaleThis); if (wxRound(scale) == scale) indexBest = indexLast; diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index c40e50124a..c90e022e6d 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -50,6 +50,15 @@ TEST_CASE("BitmapBundle::FromBitmaps", "[bmpbundle]") CHECK( b.GetBitmap(wxSize(24, 24)).GetSize() == wxSize(24, 24) ); } +TEST_CASE("BitmapBundle::GetBitmap", "[bmpbundle]") +{ + const wxBitmapBundle b = wxBitmapBundle::FromBitmap(wxBitmap(16, 16)); + + CHECK( b.GetBitmap(wxSize(16, 16)).GetSize() == wxSize(16, 16) ); + CHECK( b.GetBitmap(wxSize(32, 32)).GetSize() == wxSize(32, 32) ); + CHECK( b.GetBitmap(wxSize(24, 24)).GetSize() == wxSize(24, 24) ); +} + // Helper functions for the test below. namespace {