mirror of
https://github.com/MobileGL-Dev/MobileGlues.git
synced 2025-09-22 02:32:29 -04:00
[Fix] (cache.cpp): Prevent glsl cache loading fragment from crashing when glsl cache file is broken.
Signed-off-by: BZLZHH <admin@bzlzhh.top>
This commit is contained in:
parent
b20668c6ff
commit
2823791458
@ -150,33 +150,42 @@ void Cache::maintainCacheSize() {
|
||||
|
||||
|
||||
bool Cache::load() {
|
||||
ifstream file(GLSL_CACHE_FILE_PATH, ios::binary);
|
||||
if (!file) return false;
|
||||
try {
|
||||
ifstream file(GLSL_CACHE_FILE_PATH, ios::binary);
|
||||
if (!file) return false;
|
||||
|
||||
size_t count;
|
||||
file.read(reinterpret_cast<char*>(&count), sizeof(count));
|
||||
size_t count;
|
||||
file.read(reinterpret_cast<char*>(&count), sizeof(count));
|
||||
|
||||
while (count--) {
|
||||
array<uint8_t, 32> hash{};
|
||||
size_t esslSize;
|
||||
while (count--) {
|
||||
array<uint8_t, 32> hash{};
|
||||
size_t esslSize;
|
||||
|
||||
file.read(reinterpret_cast<char*>(hash.data()), hash.size());
|
||||
file.read(reinterpret_cast<char*>(&esslSize), sizeof(esslSize));
|
||||
file.read(reinterpret_cast<char*>(hash.data()), hash.size());
|
||||
file.read(reinterpret_cast<char*>(&esslSize), sizeof(esslSize));
|
||||
|
||||
string essl(esslSize, '\0');
|
||||
file.read(essl.data(), (long)esslSize);
|
||||
string essl(esslSize, '\0');
|
||||
file.read(essl.data(), (long)esslSize);
|
||||
|
||||
if (cacheMap.count(hash)) continue;
|
||||
if (cacheMap.count(hash)) continue;
|
||||
|
||||
size_t entryMemory = sizeof(CacheEntry::sha256) + sizeof(size_t) + esslSize;
|
||||
cacheSize += entryMemory;
|
||||
size_t entryMemory = sizeof(CacheEntry::sha256) + sizeof(size_t) + esslSize;
|
||||
cacheSize += entryMemory;
|
||||
|
||||
cacheList.emplace_back(CacheEntry{hash, move(essl), esslSize});
|
||||
cacheMap[hash] = prev(cacheList.end());
|
||||
cacheList.emplace_back(CacheEntry{hash, move(essl), esslSize});
|
||||
cacheMap[hash] = prev(cacheList.end());
|
||||
}
|
||||
|
||||
maintainCacheSize();
|
||||
return true;
|
||||
} catch (...) {
|
||||
LOG_W_FORCE("Error while loading glsl cache file. Clearing it...")
|
||||
cacheMap.clear();
|
||||
cacheSize = 0;
|
||||
cacheList.clear();
|
||||
save();
|
||||
return false;
|
||||
}
|
||||
|
||||
maintainCacheSize();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -578,7 +578,7 @@ char* GLSLtoGLSLES(char* glsl_code, GLenum glsl_type, uint essl_version, uint gl
|
||||
char* converted = glsl_version<140?GLSLtoGLSLES_1(glsl_code, glsl_type, essl_version):GLSLtoGLSLES_2(glsl_code, glsl_type, essl_version);
|
||||
if (converted && isGlslConvertedSuccessfully) {
|
||||
converted = process_uniform_declarations(converted);
|
||||
glslCache.put(sha256_string.c_str(), converted);
|
||||
glslCache.put(sha256_string.c_str(), converted);
|
||||
}
|
||||
return converted ? converted : glsl_code;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user