summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorandreykproductengine <andreykproductengine@lindenlab.com>2017-08-09 18:19:28 +0300
committerandreykproductengine <andreykproductengine@lindenlab.com>2017-08-09 18:19:28 +0300
commit654aead8a1014d095331986a32690920b6d8464a (patch)
tree222521b4173f8961dcb0483279ab7319ac5f49fe /indra
parentaea3a9c18aeaee73daf1afb93120688817e8cb6a (diff)
SL-684 Improve cache version guard
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/lltexturecache.cpp36
-rw-r--r--indra/newview/lltexturecache.h8
-rw-r--r--indra/newview/llvocache.cpp12
-rw-r--r--indra/newview/llvocache.h3
4 files changed, 51 insertions, 8 deletions
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index a541273621..5561fddb9d 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -31,6 +31,7 @@
#include "llapr.h"
#include "lldir.h"
#include "llimage.h"
+#include "llimagej2c.h" // for version control
#include "lllfsthread.h"
#include "llviewercontrol.h"
@@ -938,6 +939,14 @@ BOOL LLTextureCache::isInLocal(const LLUUID& id)
F32 LLTextureCache::sHeaderCacheVersion = 1.7f;
U32 LLTextureCache::sCacheMaxEntries = 1024 * 1024; //~1 million textures.
S64 LLTextureCache::sCacheMaxTexturesSize = 0; // no limit
+std::string LLTextureCache::sHeaderCacheEncoderVersion = LLImageJ2C::getEngineInfo();
+
+#if defined(ADDRESS_SIZE)
+U32 LLTextureCache::sHeaderCacheAddressSize = ADDRESS_SIZE;
+#else
+U32 LLTextureCache::sHeaderCacheAddressSize = 32;
+#endif
+
const char* entries_filename = "texture.entries";
const char* cache_filename = "texture.cache";
const char* old_textures_dirname = "textures";
@@ -1080,12 +1089,28 @@ void LLTextureCache::readEntriesHeader()
}
else //create an empty entries header.
{
- mHeaderEntriesInfo.mVersion = sHeaderCacheVersion ;
- mHeaderEntriesInfo.mEntries = 0 ;
+ setEntriesHeader();
writeEntriesHeader() ;
}
}
+void LLTextureCache::setEntriesHeader()
+{
+ if (sHeaderEncoderStringSize < sHeaderCacheEncoderVersion.size() + 1)
+ {
+ // For simplicity we use predefined size of header, so if version string
+ // doesn't fit, either getEngineInfo() returned malformed string or
+ // sHeaderEncoderStringSize need to be increased.
+ // Also take into accout that c_str() returns additional null character
+ LL_ERRS() << "Version string doesn't fit in header" << LL_ENDL;
+ }
+
+ mHeaderEntriesInfo.mVersion = sHeaderCacheVersion;
+ mHeaderEntriesInfo.mAdressSize = sHeaderCacheAddressSize;
+ strcpy(mHeaderEntriesInfo.mEncoderVersion, sHeaderCacheEncoderVersion.c_str());
+ mHeaderEntriesInfo.mEntries = 0;
+}
+
void LLTextureCache::writeEntriesHeader()
{
llassert_always(mHeaderAPRFile == NULL);
@@ -1439,7 +1464,9 @@ void LLTextureCache::readHeaderCache()
readEntriesHeader();
- if (mHeaderEntriesInfo.mVersion != sHeaderCacheVersion)
+ if (mHeaderEntriesInfo.mVersion != sHeaderCacheVersion
+ || mHeaderEntriesInfo.mAdressSize != sHeaderCacheAddressSize
+ || strcmp(mHeaderEntriesInfo.mEncoderVersion, sHeaderCacheEncoderVersion.c_str()) != 0)
{
if (!mReadOnly)
{
@@ -1601,8 +1628,7 @@ void LLTextureCache::purgeAllTextures(bool purge_directories)
mUpdatedEntryMap.clear();
// Info with 0 entries
- mHeaderEntriesInfo.mVersion = sHeaderCacheVersion;
- mHeaderEntriesInfo.mEntries = 0;
+ setEntriesHeader();
writeEntriesHeader();
LL_INFOS() << "The entire texture cache is cleared." << LL_ENDL ;
diff --git a/indra/newview/lltexturecache.h b/indra/newview/lltexturecache.h
index 6ff4c44568..95f9afc2bc 100644
--- a/indra/newview/lltexturecache.h
+++ b/indra/newview/lltexturecache.h
@@ -46,10 +46,13 @@ class LLTextureCache : public LLWorkerThread
private:
// Entries
+ static const U32 sHeaderEncoderStringSize = 32;
struct EntriesInfo
{
- EntriesInfo() : mVersion(0.f), mEntries(0) {}
+ EntriesInfo() : mVersion(0.f), mAdressSize(0), mEntries(0) { memset(mEncoderVersion, 0, sHeaderEncoderStringSize); }
F32 mVersion;
+ U32 mAdressSize;
+ char mEncoderVersion[sHeaderEncoderStringSize];
U32 mEntries;
};
struct Entry
@@ -156,6 +159,7 @@ private:
LLAPRFile* openHeaderEntriesFile(bool readonly, S32 offset);
void closeHeaderEntriesFile();
void readEntriesHeader();
+ void setEntriesHeader();
void writeEntriesHeader();
S32 openAndReadEntry(const LLUUID& id, Entry& entry, bool create);
bool updateEntry(S32& idx, Entry& entry, S32 new_image_size, S32 new_body_size);
@@ -224,6 +228,8 @@ private:
// Statics
static F32 sHeaderCacheVersion;
+ static U32 sHeaderCacheAddressSize;
+ static std::string sHeaderCacheEncoderVersion;
static U32 sCacheMaxEntries;
static S64 sCacheMaxTexturesSize;
};
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index fd1d57a9d0..fb28d9bdb5 100644
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -1093,11 +1093,21 @@ void LLVOCache::initCache(ELLPath location, U32 size, U32 cache_version)
}
mCacheSize = llclamp(size, MIN_ENTRIES_TO_PURGE, MAX_NUM_OBJECT_ENTRIES);
mMetaInfo.mVersion = cache_version;
+
+#if defined(ADDRESS_SIZE)
+ U32 expected_address = ADDRESS_SIZE;
+#else
+ U32 expected_address = 32;
+#endif
+ mMetaInfo.mAddressSize = expected_address;
+
readCacheHeader();
- if(mMetaInfo.mVersion != cache_version)
+ if( mMetaInfo.mVersion != cache_version
+ || mMetaInfo.mAddressSize != expected_address)
{
mMetaInfo.mVersion = cache_version ;
+ mMetaInfo.mAddressSize = expected_address;
if(mReadOnly) //disable cache
{
clearCacheInMemory();
diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h
index 7aabde1b2d..230a81fb76 100644
--- a/indra/newview/llvocache.h
+++ b/indra/newview/llvocache.h
@@ -237,9 +237,10 @@ private:
struct HeaderMetaInfo
{
- HeaderMetaInfo() : mVersion(0){}
+ HeaderMetaInfo() : mVersion(0), mAddressSize(0) {}
U32 mVersion;
+ U32 mAddressSize;
};
struct header_entry_less