diff --git a/src/renderer/tvgSaver.cpp b/src/renderer/tvgSaver.cpp index a5eaefc0..ac18dabe 100644 --- a/src/renderer/tvgSaver.cpp +++ b/src/renderer/tvgSaver.cpp @@ -157,14 +157,17 @@ Result Saver::save(unique_ptr animation, const string& path, uint32_t auto a = animation.release(); if (!a) return Result::MemoryCorruption; + //animation holds the picture, it must be 1 at the bottom. + auto remove = PP(a->picture())->refCnt <= 1 ? true : false; + if (mathZero(a->totalFrame())) { - delete(a); + if (remove) delete(a); return Result::InsufficientCondition; } //Already on saving an other resource. if (pImpl->saveModule) { - delete(a); + if (remove) delete(a); return Result::InsufficientCondition; } @@ -173,12 +176,12 @@ Result Saver::save(unique_ptr animation, const string& path, uint32_t pImpl->saveModule = saveModule; return Result::Success; } else { - delete(a); + if (remove) delete(a); delete(saveModule); return Result::Unknown; } } - delete(a); + if (remove) delete(a); return Result::NonSupport; } diff --git a/src/savers/gif/tvgGifSaver.cpp b/src/savers/gif/tvgGifSaver.cpp index b947d037..68f6af34 100644 --- a/src/savers/gif/tvgGifSaver.cpp +++ b/src/savers/gif/tvgGifSaver.cpp @@ -99,7 +99,8 @@ bool GifSaver::close() delete(bg); bg = nullptr; - delete(animation); + //animation holds the picture, it must be 1 at the bottom. + if (animation && PP(animation->picture())->refCnt <= 1) delete(animation); animation = nullptr; free(path); diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index 749a4bf1..c33a4c79 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -764,7 +764,7 @@ bool TvgSaver::close() { this->done(); - delete(paint); + if (paint && P(paint)->refCnt == 0) delete(paint); paint = nullptr; free(path);