diff --git a/src/examples/LottieExtension.cpp b/src/examples/LottieExtension.cpp index fefd526e..48ade56e 100644 --- a/src/examples/LottieExtension.cpp +++ b/src/examples/LottieExtension.cpp @@ -52,7 +52,7 @@ void tvgDrawCmds(tvg::Canvas* canvas) if (canvas->push(std::move(shape)) != tvg::Result::Success) return; - const char* slotData = R"(({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})"; + const char* slotJson = R"({"gradient_fill":{"p":{"a":0,"k":[0,0.1,0.1,0.2,1,1,0.1,0.2,0.1,1]}}})"; if (picture->load(EXAMPLE_DIR"/slotsample.json") != tvg::Result::Success) { cout << "Lottie is not supported. Did you enable Lottie Loader?" << endl; @@ -78,9 +78,12 @@ void tvgDrawCmds(tvg::Canvas* canvas) canvas->push(tvg::cast(picture)); - // Override slot data - animation->override(slotData); - canvas->update(); + //Override slot data + if (animation->override(slotJson) == tvg::Result::Success) { + canvas->update(); + } else { + cout << "Failed to override the slot" << endl; + } //Run animation loop elm_transit_duration_set(transit, animation->duration()); diff --git a/src/loaders/lottie/thorvg_lottie.h b/src/loaders/lottie/thorvg_lottie.h index ff26d2e9..a6de6dcb 100644 --- a/src/loaders/lottie/thorvg_lottie.h +++ b/src/loaders/lottie/thorvg_lottie.h @@ -23,9 +23,9 @@ public: ~LottieAnimation(); /** - * @brief Rewrite lottie properties through the slot data + * @brief Override Lottie properties using slot data. * - * @param[in] slot The lottie slot data + * @param[in] slot The Lottie slot data in JSON format. * * @retval Result::Success When succeed. * @retval Result::InsufficientCondition When the given parameter is invalid. diff --git a/src/loaders/lottie/tvgLottieLoader.cpp b/src/loaders/lottie/tvgLottieLoader.cpp index da5ba729..b53e75a7 100644 --- a/src/loaders/lottie/tvgLottieLoader.cpp +++ b/src/loaders/lottie/tvgLottieLoader.cpp @@ -304,19 +304,25 @@ bool LottieLoader::override(const char* slot) { if (!slot) return false; + //TODO: Crashed, does this necessary? + auto temp = strdup(slot); + //parsing slot json - LottieParser parser(slot, dirName); + LottieParser parser(temp, dirName); auto sid = parser.sid(); - if (!sid) return false; + if (!sid) { + free(temp); + return false; + } bool ret = false; - for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) { - if (!strcmp((*s)->sid, sid)) continue; + if (strcmp((*s)->sid, sid)) continue; ret = parser.parse(*s); break; } + free(temp); return ret; } diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 0945c90e..4af59f1c 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -253,7 +253,8 @@ struct LottieGenericProperty : LottieProperty { //shallow copy, used for slot overriding delete(frames); - *this = other; + frames = other.frames; + value = other.value; const_cast(other).frames = nullptr; return *this; } @@ -446,7 +447,9 @@ struct LottieColorStop : LottieProperty { //shallow copy, used for slot overriding delete(frames); - *this = other; + frames = other.frames; + value = other.value; + count = other.count; const_cast(other).frames = nullptr; return *this; } @@ -566,7 +569,8 @@ struct LottieTextDoc : LottieProperty { //shallow copy, used for slot overriding delete(frames); - *this = other; + frames = other.frames; + value = other.value; const_cast(other).frames = nullptr; return *this; }