diff --git a/src/renderer/tvgLoader.cpp b/src/renderer/tvgLoader.cpp index 0312504b..1f6029e7 100644 --- a/src/renderer/tvgLoader.cpp +++ b/src/renderer/tvgLoader.cpp @@ -294,15 +294,24 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid) { *invalid = false; - if (auto loader = _findFromCache(path)) return loader; + //TODO: lottie is not sharable. + auto allowCache = true; + auto ext = path.substr(path.find_last_of(".") + 1); + if (!ext.compare("json")) allowCache = false; + + if (allowCache) { + if (auto loader = _findFromCache(path)) return loader; + } if (auto loader = _findByPath(path)) { if (loader->open(path)) { - loader->hashpath = strdup(path.c_str()); - loader->pathcache = true; - { - ScopedLock lock(key); - _activeLoaders.back(loader); + if (allowCache) { + loader->hashpath = strdup(path.c_str()); + loader->pathcache = true; + { + ScopedLock lock(key); + _activeLoaders.back(loader); + } } return loader; } @@ -312,11 +321,13 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid) for (int i = 0; i < static_cast(FileType::Raw); i++) { if (auto loader = _find(static_cast(i))) { if (loader->open(path)) { - loader->hashpath = strdup(path.c_str()); - loader->pathcache = true; - { - ScopedLock lock(key); - _activeLoaders.back(loader); + if (allowCache) { + loader->hashpath = strdup(path.c_str()); + loader->pathcache = true; + { + ScopedLock lock(key); + _activeLoaders.back(loader); + } } return loader; } @@ -353,7 +364,15 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim { //Note that users could use the same data pointer with the different content. //Thus caching is only valid for shareable. - if (!copy) { + auto allowCache = !copy; + + //TODO: lottie is not sharable. + if (allowCache) { + auto type = _convert(mimeType); + if (type == FileType::Lottie) allowCache = false; + } + + if (allowCache) { if (auto loader = _findFromCache(data, size, mimeType)) return loader; } @@ -361,7 +380,7 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim if (!mimeType.empty()) { if (auto loader = _findByType(mimeType)) { if (loader->open(data, size, copy)) { - if (!copy) { + if (allowCache) { loader->hashkey = HASH_KEY(data); ScopedLock lock(key); _activeLoaders.back(loader); @@ -378,7 +397,7 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim auto loader = _find(static_cast(i)); if (loader) { if (loader->open(data, size, copy)) { - if (!copy) { + if (allowCache) { loader->hashkey = HASH_KEY(data); ScopedLock lock(key); _activeLoaders.back(loader);