loader/lottie: enhance stability

Addressed corner cases to prevent memory violations.
This commit is contained in:
Hermet Park 2023-08-11 12:19:11 +09:00 committed by Hermet Park
parent 03976b02b3
commit 374a125280
2 changed files with 7 additions and 4 deletions

View file

@ -240,8 +240,11 @@ static void _updateImage(LottieGroup* parent, LottieImage* image, int32_t frameN
{ {
auto picture = Picture::gen(); auto picture = Picture::gen();
if (image->size > 0) picture->load((const char*)image->b64Data, image->size, image->mimeType, false); if (image->size > 0) {
else picture->load(image->path); if (picture->load((const char*)image->b64Data, image->size, image->mimeType, false) != Result::Success) return;
} else {
if (picture->load(image->path) != Result::Success) return;
}
if (baseShape) { if (baseShape) {
picture->transform(baseShape->transform()); picture->transform(baseShape->transform());
@ -444,7 +447,7 @@ bool LottieBuilder::update(LottieComposition* comp, int32_t frameNo)
void LottieBuilder::build(LottieComposition* comp) void LottieBuilder::build(LottieComposition* comp)
{ {
if (comp->scene) return; if (!comp || comp->scene) return;
comp->scene = Scene::gen().release(); comp->scene = Scene::gen().release();
if (!comp->scene) return; if (!comp->scene) return;

View file

@ -265,7 +265,7 @@ bool LottieLoader::close()
unique_ptr<Paint> LottieLoader::paint() unique_ptr<Paint> LottieLoader::paint()
{ {
this->done(); this->done();
if (!comp) return nullptr;
return cast<Paint>(comp->scene); return cast<Paint>(comp->scene);
} }