lottie/loader: Fix crash when parsing error

When parsing error, lottie loader raises runtime crash.
Check whether the composition is nullptr.
This commit is contained in:
Jinny You 2024-04-15 22:21:26 +09:00 committed by Hermet Park
parent c69049ad78
commit 557de3eb40

View file

@ -350,6 +350,7 @@ float LottieLoader::duration()
if (segmentBegin == 0.0f && segmentEnd == 1.0f) return frameDuration;
if (!comp) done();
if (!comp) return 0.0f;
auto frameNo = frameCnt * (segmentEnd - segmentBegin);
return frameNo / comp->frameRate;
@ -365,6 +366,7 @@ void LottieLoader::sync()
uint32_t LottieLoader::markersCnt()
{
if (!comp) done();
if (!comp) return 0;
return comp->markers.count;
}
@ -372,7 +374,7 @@ uint32_t LottieLoader::markersCnt()
const char* LottieLoader::markers(uint32_t index)
{
if (!comp) done();
if (index < 0 || index >= markersCnt()) return nullptr;
if (!comp || index < 0 || index >= markersCnt()) return nullptr;
auto marker = comp->markers.begin() + index;
return (*marker)->name;
}
@ -381,6 +383,7 @@ const char* LottieLoader::markers(uint32_t index)
bool LottieLoader::segment(const char* marker, float& begin, float& end)
{
if (!comp) done();
if (!comp) return false;
for (auto m = comp->markers.begin(); m < comp->markers.end(); ++m) {
if (!strcmp(marker, (*m)->name)) {