Texturecache bugs! "cache_size -= entries[idx].mBodySize" must happen before removeEntry in LLTextureCache::purgeTextures, as removeEntry zeros "entries[idx].mBodySize". "mTexturesSizeTotal -= entry.mBodySize"; must happen before "entry.mBodySize = 0" in LLTextureCache::removeEntry because, well, duh.

This commit is contained in:
Shyotl
2012-04-12 10:35:42 -05:00
parent b49ad1cd34
commit 18ac23554f

View File

@@ -1415,22 +1415,21 @@ void LLTextureCache::readHeaderCache()
}
}
}
if (num_entries > sCacheMaxEntries)
if (num_entries - empty_entries > sCacheMaxEntries)
{
// Special case: cache size was reduced, need to remove entries
// Note: After we prune entries, we will call this again and create the LRU
U32 entries_to_purge = (num_entries - empty_entries) - sCacheMaxEntries;
llinfos << "Texture Cache Entries: " << num_entries << " Max: " << sCacheMaxEntries << " Empty: " << empty_entries << " Purging: " << entries_to_purge << llendl;
if (entries_to_purge > 0)
{
for (std::set<lru_data_t>::iterator iter = lru.begin(); iter != lru.end(); ++iter)
// We can exit the following loop with the given condition, since if we'd reach the end of the lru set we'd have:
// purge_list.size() = lru.size() = num_entries - empty_entries = entries_to_purge + sCacheMaxEntries >= entries_to_purge
// So, it's certain that iter will never reach lru.end() first.
std::set<lru_data_t>::iterator iter = lru.begin();
while (purge_list.size() < entries_to_purge)
{
purge_list.insert(iter->second);
if (purge_list.size() >= entries_to_purge)
break;
++iter;
}
}
llassert_always(purge_list.size() >= entries_to_purge);
}
else
{
@@ -1636,9 +1635,9 @@ void LLTextureCache::purgeTextures(bool validate)
if (purge_entry)
{
purge_count++;
LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL;
removeEntry(idx, entries[idx], filename) ;
LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL;
cache_size -= entries[idx].mBodySize;
removeEntry(idx, entries[idx], filename) ;
}
}
@@ -1652,7 +1651,7 @@ void LLTextureCache::purgeTextures(bool validate)
LL_INFOS("TextureCache") << "TEXTURE CACHE:"
<< " PURGED: " << purge_count
<< " ENTRIES: " << num_entries
<< " CACHE SIZE: " << mTexturesSizeTotal / 1024*1024 << " MB"
<< " CACHE SIZE: " << mTexturesSizeTotal / (1024 * 1024) << " MB"
<< llendl;
}
@@ -1875,14 +1874,13 @@ void LLTextureCache::removeEntry(S32 idx, Entry& entry, std::string& filename)
file_maybe_exists = false;
}
}
mTexturesSizeTotal -= entry.mBodySize;
entry.mImageSize = -1;
entry.mBodySize = 0;
mHeaderIDMap.erase(entry.mID);
mTexturesSizeMap.erase(entry.mID);
mTexturesSizeTotal -= entry.mBodySize;
mFreeList.insert(idx);
mTexturesSizeMap.erase(entry.mID);
mFreeList.insert(idx);
}
if (file_maybe_exists)