mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 21:53:41 +00:00
loader/lottie: ++safety
- add an execeptional hanlding at parsing the assets. - The precomp layer failed to prepare its instance in the parsing stage. This corrects the mistake.
This commit is contained in:
parent
9db9e003ba
commit
6f8504d3b9
4 changed files with 15 additions and 23 deletions
|
@ -31,7 +31,6 @@
|
|||
|
||||
struct Animation::Impl
|
||||
{
|
||||
//TODO: Memory Safety
|
||||
Picture picture;
|
||||
};
|
||||
|
||||
|
@ -41,7 +40,7 @@ struct Animation::Impl
|
|||
|
||||
Animation::~Animation()
|
||||
{
|
||||
|
||||
//FIXME: free pImpl
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -370,15 +370,15 @@ static void _buildReference(LottieComposition* comp, LottieLayer* layer)
|
|||
{
|
||||
for (auto asset = comp->assets.data; asset < comp->assets.end(); ++asset) {
|
||||
if (strcmp(layer->refId, (*asset)->name)) continue;
|
||||
auto assetLayer = static_cast<LottieLayer*>(*asset);
|
||||
if (layer->type == LottieLayer::Precomp) {
|
||||
auto assetLayer = static_cast<LottieLayer*>(*asset);
|
||||
if (_buildPrecomp(comp, assetLayer)) {
|
||||
layer->children = assetLayer->children;
|
||||
}
|
||||
} else if (layer->type == LottieLayer::Image) {
|
||||
layer->children.push(*asset);
|
||||
}
|
||||
layer->statical &= assetLayer->statical;
|
||||
layer->statical &= (*asset)->statical;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -349,12 +349,6 @@ struct LottieLayer : LottieGroup
|
|||
{
|
||||
enum Type : uint8_t {Precomp = 0, Solid, Image, Null, Shape, Text};
|
||||
|
||||
LottieLayer()
|
||||
{
|
||||
autoOrient = false;
|
||||
mask = false;
|
||||
}
|
||||
|
||||
~LottieLayer()
|
||||
{
|
||||
if (refId) {
|
||||
|
@ -418,9 +412,8 @@ struct LottieLayer : LottieGroup
|
|||
} cache;
|
||||
|
||||
Type type = Null;
|
||||
|
||||
bool autoOrient : 1;
|
||||
bool mask : 1;
|
||||
bool autoOrient = false;
|
||||
bool mask = false;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -806,9 +806,6 @@ void LottieParser::parseObject(LottieGroup* parent)
|
|||
|
||||
LottieImage* LottieParser::parseImage(const char* key)
|
||||
{
|
||||
auto image = new LottieImage;
|
||||
if (!image) return nullptr;
|
||||
|
||||
//Used for Image Asset
|
||||
const char* data = nullptr;
|
||||
const char* subPath = nullptr;
|
||||
|
@ -821,15 +818,14 @@ LottieImage* LottieParser::parseImage(const char* key)
|
|||
data = getString();
|
||||
} else if (!strcmp(key, "e")) {
|
||||
embedded = getInt();
|
||||
#if 0
|
||||
} else if (!strcmp(key, "w")) {
|
||||
auto w = getInt();
|
||||
} else if (!strcmp(key, "h")) {
|
||||
auto h = getInt();
|
||||
#endif
|
||||
} else skip(key);
|
||||
} while ((key = nextObjectKey()));
|
||||
|
||||
if (!data) return nullptr;
|
||||
|
||||
auto image = new LottieImage;
|
||||
if (!image) return nullptr;
|
||||
|
||||
//embeded image resource. should start with "data:"
|
||||
//header look like "data:image/png;base64," so need to skip till ','.
|
||||
if (embedded && !strncmp(data, "data:", 5)) {
|
||||
|
@ -877,13 +873,15 @@ LottieObject* LottieParser::parseAsset()
|
|||
//Precomposition asset
|
||||
} else if (!strcmp(key, "layers")) {
|
||||
obj = parseLayers();
|
||||
} else if (!strcmp(key, "w") || !strcmp(key, "h") || !strcmp(key, "nm") || !strcmp(key, "fr")) {
|
||||
skip(key);
|
||||
//Image asset
|
||||
} else {
|
||||
obj = parseImage(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
obj->name = id;
|
||||
if (obj) obj->name = id;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -1007,6 +1005,8 @@ LottieLayer* LottieParser::parseLayers()
|
|||
root->children.push(layer);
|
||||
}
|
||||
}
|
||||
|
||||
root->prepare();
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue