From 4a29c739af6299c51963c4f5c63fd49f113a74be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 15 Oct 2008 14:45:51 +0000 Subject: [PATCH] * When adding new bitmaps, Pairs now checks if it already got it (in case two apps are using the same icon). * This fixes bug #2694. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28133 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/pairs/PairsView.cpp | 20 +++++++++++++++++--- src/apps/pairs/PairsView.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) 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];