From f22c2be51122978c8a85a4330a6d781410a8415e Mon Sep 17 00:00:00 2001 From: nokeya Date: Wed, 23 Sep 2020 15:55:41 +0300 Subject: [PATCH] allow empty key --- inc/rlottie.h | 4 ++-- src/lottie/lottieloader.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/inc/rlottie.h b/inc/rlottie.h index 67565691..b527bf48 100644 --- a/inc/rlottie.h +++ b/inc/rlottie.h @@ -305,8 +305,8 @@ class RLOTTIE_API Animation { * @internal */ static std::unique_ptr - loadFromData(std::string jsonData, const std::string &key, - const std::string &resourcePath="", bool cachePolicy=true); + loadFromData(std::string jsonData, const std::string &key = std::string(), + const std::string &resourcePath = std::string(), bool cachePolicy=true); /** * @brief Constructs an animation object from JSON string data and update. diff --git a/src/lottie/lottieloader.cpp b/src/lottie/lottieloader.cpp index 8a52949e..68adf605 100644 --- a/src/lottie/lottieloader.cpp +++ b/src/lottie/lottieloader.cpp @@ -148,7 +148,7 @@ std::shared_ptr model::loadFromData( std::string jsonData, const std::string &key, std::string resourcePath, bool cachePolicy) { - if (cachePolicy) { + if (cachePolicy && !key.empty()) { auto obj = ModelCache::instance().find(key); if (obj) return obj; } @@ -156,7 +156,8 @@ std::shared_ptr model::loadFromData( auto obj = internal::model::parse(const_cast(jsonData.c_str()), std::move(resourcePath)); - if (obj && cachePolicy) ModelCache::instance().add(key, obj); + if (obj && cachePolicy && !key.empty()) + ModelCache::instance().add(key, obj); return obj; }