diff --git a/src/bindings/wasm/tvgWasmLottieAnimation.cpp b/src/bindings/wasm/tvgWasmLottieAnimation.cpp index ce9719cb..d46589b8 100644 --- a/src/bindings/wasm/tvgWasmLottieAnimation.cpp +++ b/src/bindings/wasm/tvgWasmLottieAnimation.cpp @@ -22,6 +22,7 @@ #include #include +#include "tvgPicture.h" using namespace emscripten; using namespace std; @@ -234,26 +235,25 @@ public: if (!animation) return false; - auto duplicate = cast(animation->picture()->duplicate()); - - if (!duplicate) { - errorMsg = "duplicate(), fail"; - return false; - } - auto saver = Saver::gen(); if (!saver) { errorMsg = "Invalid saver"; return false; } - if (saver->save(std::move(duplicate), "output.tvg") != tvg::Result::Success) { + //preserve the picture using the reference counting + PP(animation->picture())->ref(); + + if (saver->save(tvg::cast(animation->picture()), "output.tvg") != tvg::Result::Success) { + PP(animation->picture())->unref(); errorMsg = "save(), fail"; return false; } saver->sync(); + PP(animation->picture())->unref(); + return true; }