diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index e2e9fc00a2..b3faf49f2e 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -150,16 +150,14 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize& int wxGenericImageList::Add( const wxBitmap &bitmap ) { - // We use the scaled, i.e. logical, size here as image list images size is - // specified in logical pixels, just as window coordinates and sizes are. - const wxSize bitmapSize = bitmap.GetScaledSize(); - + // Cannot add image to invalid list if ( m_size == wxSize(0, 0) ) + return -1; + + if ( m_images.empty() ) { - // This is the first time Add() is called and we hadn't had any fixed - // size: adopt the size of our first bitmap as image size. - m_size = bitmapSize; - // Save scale factor to check if all images have the same scaling + // This is the first time Add() is called so we should save + // scale factor to check if further images will have the same scaling m_scaleFactor = bitmap.GetScaleFactor(); } else if ( bitmap.GetScaleFactor() != m_scaleFactor ) @@ -168,6 +166,10 @@ int wxGenericImageList::Add( const wxBitmap &bitmap ) return -1; } + // We use the scaled, i.e. logical, size here as image list images size is + // specified in logical pixels, just as window coordinates and sizes are. + const wxSize bitmapSize = bitmap.GetScaledSize(); + // There is a special case: a bitmap may contain more than one image, // in which case we're supposed to chop it in parts, just as Windows // ImageList_Add() does.