mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
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:
parent
c69049ad78
commit
557de3eb40
1 changed files with 4 additions and 1 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue