mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 12:34:30 +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
1bbf9bbb7d
commit
54eedd4bb6
1 changed files with 4 additions and 1 deletions
|
@ -354,6 +354,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;
|
||||||
|
@ -369,6 +370,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +378,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;
|
||||||
}
|
}
|
||||||
|
@ -385,6 +387,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