mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
lottie/expressions: enhance stability
When the system fails to interpret the expression code, it forcibly disables the feature per property. This improvement enhances stability and performance by avoiding reckless attempts to interpret JavaScript code. When we confirm the full stability with expressions, we can revert this code.
This commit is contained in:
parent
fca4ef3109
commit
027e0fd6f0
3 changed files with 11 additions and 5 deletions
|
@ -1219,7 +1219,10 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp)
|
|||
//evaluate the code
|
||||
auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS);
|
||||
|
||||
if (jerry_value_is_exception(eval)) return jerry_undefined();
|
||||
if (jerry_value_is_exception(eval)) {
|
||||
exp->enabled = false; // The feature is experimental, it will be forcely turned off if it's incompatible.
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
jerry_value_free(eval);
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ static LottieExpression* _expression(char* code, LottieComposition* comp, Lottie
|
|||
inst->object = object;
|
||||
inst->property = property;
|
||||
inst->type = type;
|
||||
inst->enabled = true;
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
|
|
@ -194,6 +194,8 @@ struct LottieExpression
|
|||
LottieProperty* property;
|
||||
LottieProperty::Type type;
|
||||
|
||||
bool enabled;
|
||||
|
||||
struct {
|
||||
uint32_t key = 0; //the keyframe number repeating to
|
||||
float in = FLT_MAX; //looping duration in frame number
|
||||
|
@ -367,7 +369,7 @@ struct LottieGenericProperty : LottieProperty
|
|||
T operator()(float frameNo, LottieExpressions* exps)
|
||||
{
|
||||
T out{};
|
||||
if (exps && exp) {
|
||||
if (exps && (exp && exp->enabled)) {
|
||||
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
|
||||
if (exps->result<LottieGenericProperty<T>>(frameNo, out, exp)) return out;
|
||||
}
|
||||
|
@ -507,7 +509,7 @@ struct LottiePathSet : LottieProperty
|
|||
|
||||
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, LottieExpressions* exps)
|
||||
{
|
||||
if (exps && exp) {
|
||||
if (exps && (exp && exp->enabled)) {
|
||||
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
|
||||
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, exp)) return true;
|
||||
}
|
||||
|
@ -588,7 +590,7 @@ struct LottieColorStop : LottieProperty
|
|||
|
||||
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps)
|
||||
{
|
||||
if (exps && exp) {
|
||||
if (exps && (exp && exp->enabled)) {
|
||||
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
|
||||
if (exps->result<LottieColorStop>(frameNo, fill, exp)) return Result::Success;
|
||||
}
|
||||
|
@ -724,7 +726,7 @@ struct LottiePosition : LottieProperty
|
|||
Point operator()(float frameNo, LottieExpressions* exps)
|
||||
{
|
||||
Point out{};
|
||||
if (exps && exp) {
|
||||
if (exps && (exp && exp->enabled)) {
|
||||
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
|
||||
if (exps->result<LottiePosition>(frameNo, out, exp)) return out;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue