diff --git a/src/apps/pairs/PairsView.cpp b/src/apps/pairs/PairsView.cpp index e612f2cae7..bf084c1ba7 100644 --- a/src/apps/pairs/PairsView.cpp +++ b/src/apps/pairs/PairsView.cpp @@ -69,6 +69,21 @@ PairsView::AttachedToWindow() } +bool +PairsView::_HasBitmap(BList& bitmaps, BBitmap* bitmap) +{ + // TODO: if this takes too long, we could build a hash value for each + // bitmap in a separate list + for (int32 i = bitmaps.CountItems(); i-- > 0;) { + BBitmap* item = (BBitmap*)bitmaps.ItemAtFast(i); + if (!memcmp(item->Bits(), bitmap->Bits(), item->BitsLength())) + return true; + } + + return false; +} + + void PairsView::_ReadRandomIcons() { @@ -125,10 +140,9 @@ PairsView::_ReadRandomIcons() delete[] data; - if (!bitmaps.AddItem(bitmap)) + if (_HasBitmap(bitmaps, bitmap) || !bitmaps.AddItem(bitmap)) delete bitmap; - - if (bitmaps.CountItems() >= 128) { + else if (bitmaps.CountItems() >= 128) { // this is enough to choose from, stop eating memory... break; } diff --git a/src/apps/pairs/PairsView.h b/src/apps/pairs/PairsView.h index e5f4137b90..cdce7df4f0 100644 --- a/src/apps/pairs/PairsView.h +++ b/src/apps/pairs/PairsView.h @@ -28,6 +28,7 @@ private: void _SetPairsBoard(); void _ReadRandomIcons(); void _GenerateCardPos(); + bool _HasBitmap(BList& bitmaps, BBitmap* bitmap); BMessage* fButtonMessage; BBitmap* fCard[8];