Skip to content

Commit

Permalink
Fix the issue of mistakenly deleting all purgeable resources, even wh…
Browse files Browse the repository at this point in the history
…en the maximum byte limit is not reached. (#131)
  • Loading branch information
domchen committed Jan 30, 2024
1 parent d864aee commit f34a005
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/gpu/ResourceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Resource* ResourceCache::getUniqueResource(const ResourceKey& resourceKey) {
}

void ResourceCache::AddToList(std::list<Resource*>& list, Resource* resource) {
list.push_front(resource);
list.push_back(resource);
resource->cachedList = &list;
resource->cachedPosition = list.begin();
resource->cachedPosition = --list.end();
}

void ResourceCache::RemoveFromList(std::list<Resource*>& list, Resource* resource) {
Expand Down Expand Up @@ -197,21 +197,20 @@ bool ResourceCache::purgeUntilMemoryTo(size_t bytesLimit, bool recycledResourceO
void ResourceCache::purgeResourcesByLRU(bool recycledResourceOnly,
const std::function<bool(Resource*)>& satisfied) {
processUnreferencedResources();
std::vector<Resource*> needToPurge = {};
for (auto item = purgeableResources.rbegin(); item != purgeableResources.rend(); item++) {
auto item = purgeableResources.begin();
while (item != purgeableResources.end()) {
auto* resource = *item;
if (satisfied(resource)) {
break;
}
if (!recycledResourceOnly || !resource->hasExternalReferences()) {
needToPurge.push_back(resource);
item = purgeableResources.erase(item);
purgeableBytes -= resource->memoryUsage();
removeResource(resource);
} else {
item++;
}
}
for (auto& resource : needToPurge) {
RemoveFromList(purgeableResources, resource);
purgeableBytes -= resource->memoryUsage();
removeResource(resource);
}
}

void ResourceCache::processUnreferencedResources() {
Expand Down

0 comments on commit f34a005

Please sign in to comment.