From df942b3eb1d49d2928d957f9adaf282cdb4be665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 18 Nov 2010 16:48:14 +0000 Subject: [PATCH] * Always make sure the reference to the bitmap is actually released. This should fix bug #6824. * Don't queue more pictures if we can only use a single CPU, and the queue is already busy. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39486 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ImageCache.cpp | 20 ++++++++++++-------- src/apps/showimage/ShowImageWindow.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/apps/showimage/ImageCache.cpp b/src/apps/showimage/ImageCache.cpp index 165ff1ce8b..7eb6fec1d6 100644 --- a/src/apps/showimage/ImageCache.cpp +++ b/src/apps/showimage/ImageCache.cpp @@ -95,10 +95,11 @@ ImageCache::RetrieveImage(const entry_ref& ref, int32 page, QueueEntry* entry; if (findQueue == fQueueMap.end()) { - if (target == NULL && fCacheMap.size() < 5 - && fBytes > fMaxBytes * 1 / 2) { + if (target == NULL + && ((fCacheMap.size() < 5 && fBytes > fMaxBytes * 1 / 2) + || (fMaxThreadCount == 1 && fQueueMap.size() > 1))) { // Don't accept any further precaching if we're low on memory - // anyway. + // anyway, or if there is already a busy queue. return B_NO_MEMORY; } @@ -290,7 +291,10 @@ ImageCache::_NotifyListeners(CacheEntry* entry, QueueEntry* queueEntry) std::set::iterator iterator = queueEntry->listeners.begin(); for (; iterator != queueEntry->listeners.end(); iterator++) { - iterator->SendMessage(¬ification); + if (iterator->SendMessage(¬ification) == B_OK) { + entry->bitmapOwner->AcquireReference(); + // this is the reference owned by the target + } } } @@ -304,7 +308,10 @@ ImageCache::_NotifyTarget(CacheEntry* entry, const BMessenger* target) BMessage notification(kMsgImageCacheImageLoaded); _BuildNotification(entry, notification); - target->SendMessage(¬ification); + if (target->SendMessage(¬ification) == B_OK) { + entry->bitmapOwner->AcquireReference(); + // this is the reference owned by the target + } } @@ -314,9 +321,6 @@ ImageCache::_BuildNotification(CacheEntry* entry, BMessage& message) if (entry == NULL) return; - entry->bitmapOwner->AcquireReference(); - // this is the reference owned by the target - message.AddString("type", entry->type); message.AddString("mime", entry->mimeType); message.AddRef("ref", &entry->ref); diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index 034f9fd913..3c031cd42a 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -521,16 +521,24 @@ ShowImageWindow::MessageReceived(BMessage* message) { fProgressWindow->Stop(); + BitmapOwner* bitmapOwner = NULL; + message->FindPointer("bitmapOwner", (void**)&bitmapOwner); + bool first = fImageView->Bitmap() == NULL; entry_ref ref; message->FindRef("ref", &ref); if (!first && ref != fNavigator.CurrentRef()) { // ignore older images + if (bitmapOwner != NULL) + bitmapOwner->ReleaseReference(); break; } status_t status = fImageView->SetImage(message); if (status != B_OK) { + if (bitmapOwner != NULL) + bitmapOwner->ReleaseReference(); + _LoadError(ref); // quit if file could not be opened