diff --git a/src/app/file_system.cpp b/src/app/file_system.cpp index f9bad76a4..e9d64950b 100644 --- a/src/app/file_system.cpp +++ b/src/app/file_system.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -71,7 +71,7 @@ unsigned int current_file_system_version = 0; #endif // a position in the file-system -class FileItem : public IFileItem { +class FileItem final : public IFileItem { public: // TODO make all these fields private std::string m_keyname; @@ -123,6 +123,13 @@ public: m_thumbnailProgress = progress; } + bool needThumbnail() const override { + return + !isBrowsable() && + m_thumbnail == nullptr && + m_thumbnailProgress < 1.0; + } + os::SurfaceRef getThumbnail() override; void setThumbnail(const os::SurfaceRef& thumbnail) override; @@ -593,6 +600,8 @@ os::SurfaceRef FileItem::getThumbnail() void FileItem::setThumbnail(const os::SurfaceRef& newThumbnail) { + m_thumbnailProgress = 1.0; + if (newThumbnail) newThumbnail->ref(); auto old = m_thumbnail.exchange(newThumbnail.get()); diff --git a/src/app/file_system.h b/src/app/file_system.h index 5650ac4f3..ebe75c597 100644 --- a/src/app/file_system.h +++ b/src/app/file_system.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -87,8 +87,10 @@ namespace app { virtual double getThumbnailProgress() = 0; virtual void setThumbnailProgress(double progress) = 0; + virtual bool needThumbnail() const = 0; virtual os::SurfaceRef getThumbnail() = 0; virtual void setThumbnail(const os::SurfaceRef& thumbnail) = 0; + }; } // namespace app diff --git a/src/app/thumbnail_generator.cpp b/src/app/thumbnail_generator.cpp index 85b6af900..725ef3c84 100644 --- a/src/app/thumbnail_generator.cpp +++ b/src/app/thumbnail_generator.cpp @@ -176,17 +176,26 @@ private: THUMB_TRACE("FOP done with thumbnail: %s %s\n", m_item.fileitem->fileName().c_str(), (m_fop->isStop() ? " (stop)": "")); - - // Reset the m_item (first the fileitem so this worker is not - // associated to this fileitem anymore, and then the FileOp). - { - std::lock_guard lock(m_mutex); - m_item.fileitem = nullptr; - } } catch (const std::exception& e) { m_fop->setError("Error loading file:\n%s", e.what()); } + + if (!m_fop->isStop()) { + // Set a nullptr thumbnail if we failed loading the given file, + // in this way we're not going to re-try generating this same + // thumbnail. + if (m_item.fileitem->needThumbnail()) + m_item.fileitem->setThumbnail(nullptr); + } + + // Reset the m_item (first the fileitem so this worker is not + // associated to this fileitem anymore, and then the FileOp). + { + std::lock_guard lock(m_mutex); + m_item.fileitem = nullptr; + } + m_fop->done(); { std::lock_guard lock(m_mutex); @@ -262,8 +271,7 @@ bool ThumbnailGenerator::checkWorkers() void ThumbnailGenerator::generateThumbnail(IFileItem* fileitem) { - if (fileitem->isBrowsable() || - fileitem->getThumbnail()) + if (!fileitem->needThumbnail()) return; if (fileitem->getThumbnailProgress() > 0.0) { @@ -302,11 +310,12 @@ void ThumbnailGenerator::generateThumbnail(IFileItem* fileitem) fileitem->fileName().c_str(), FILE_LOAD_SEQUENCE_NONE | FILE_LOAD_ONE_FRAME)); - if (!fop) - return; - - if (fop->hasError()) + if (!fop || fop->hasError()) { + // Set a nullptr thumbnail so we don't try to generate a thumbnail + // for this fileitem again. + fileitem->setThumbnail(nullptr); return; + } m_remainingItems.push(Item(fileitem, fop.get())); fop.release(); diff --git a/src/app/ui/file_list.cpp b/src/app/ui/file_list.cpp index 15e511039..162a3594c 100644 --- a/src/app/ui/file_list.cpp +++ b/src/app/ui/file_list.cpp @@ -885,7 +885,7 @@ void FileList::selectIndex(int index) void FileList::generateThumbnailForFileItem(IFileItem* fi) { - if (fi && animation() == ANI_NONE) { + if (fi && fi->needThumbnail() && animation() == ANI_NONE) { auto it = std::find(m_generateThumbnailsForTheseItems.begin(), m_generateThumbnailsForTheseItems.end(), fi); if (it != m_generateThumbnailsForTheseItems.end())