Fix OpenGL texture cache "leak" and slightly tweak hash string construction.

The leak happened because a struct was hashed that had uninitialized
bytes in padding inserted by the compiler. The hash string in now constructed
as concatenation of three CRC32s as 8-byte hex strings, i.e. the individual
CRC32s are padded with leading zeros.

Note to users: because of the hash change, it's sensible to delete the
'textures' and 'textures.cache' files.

git-svn-id: https://svn.eduke32.com/eduke32@4096 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-10-11 22:20:46 +00:00
parent 66064a33f3
commit b427a5f941

View file

@ -399,9 +399,13 @@ int32_t texcache_readdata(void *dest, int32_t len)
static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t len, const int32_t dameth, const char effect)
{
// Assert that BMAX_PATH is a multiple of 4 so that struct texcacheid_t
// gets no padding inserted by the compiler.
EDUKE32_STATIC_ASSERT((BMAX_PATH & 3) == 0);
struct texcacheid_t {
int32_t len, method;
char effect, name[BMAX_PATH];
char effect, name[BMAX_PATH+3]; // +3: pad to a multiple of 4
} id = { len, dameth, effect, "" };
Bstrcpy(id.name, fn);
@ -409,7 +413,7 @@ static const char * texcache_calcid(char *cachefn, const char *fn, const int32_t
while (Bstrlen(id.name) < BMAX_PATH - Bstrlen(fn))
Bstrcat(id.name, fn);
Bsprintf(cachefn, "%x%x%x",
Bsprintf(cachefn, "%08x%08x%08x",
crc32once((uint8_t *)fn, Bstrlen(fn)),
crc32once((uint8_t *)id.name, Bstrlen(id.name)),
crc32once((uint8_t *)&id, sizeof(struct texcacheid_t)));