mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +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 (segmentBegin == 0.0f && segmentEnd == 1.0f) return frameDuration;
|
||||||
|
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
|
if (!comp) return 0.0f;
|
||||||
|
|
||||||
auto frameNo = frameCnt * (segmentEnd - segmentBegin);
|
auto frameNo = frameCnt * (segmentEnd - segmentBegin);
|
||||||
return frameNo / comp->frameRate;
|
return frameNo / comp->frameRate;
|
||||||
|
@ -365,6 +366,7 @@ void LottieLoader::sync()
|
||||||
uint32_t LottieLoader::markersCnt()
|
uint32_t LottieLoader::markersCnt()
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
|
if (!comp) return 0;
|
||||||
return comp->markers.count;
|
return comp->markers.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +374,7 @@ uint32_t LottieLoader::markersCnt()
|
||||||
const char* LottieLoader::markers(uint32_t index)
|
const char* LottieLoader::markers(uint32_t index)
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
if (index < 0 || index >= markersCnt()) return nullptr;
|
if (!comp || index < 0 || index >= markersCnt()) return nullptr;
|
||||||
auto marker = comp->markers.begin() + index;
|
auto marker = comp->markers.begin() + index;
|
||||||
return (*marker)->name;
|
return (*marker)->name;
|
||||||
}
|
}
|
||||||
|
@ -381,6 +383,7 @@ const char* LottieLoader::markers(uint32_t index)
|
||||||
bool LottieLoader::segment(const char* marker, float& begin, float& end)
|
bool LottieLoader::segment(const char* marker, float& begin, float& end)
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
|
if (!comp) return false;
|
||||||
|
|
||||||
for (auto m = comp->markers.begin(); m < comp->markers.end(); ++m) {
|
for (auto m = comp->markers.begin(); m < comp->markers.end(); ++m) {
|
||||||
if (!strcmp(marker, (*m)->name)) {
|
if (!strcmp(marker, (*m)->name)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue