From 81ff238fef1148a921630041123c715da74ab924 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 4 May 2024 15:19:26 +0900 Subject: [PATCH] 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. --- src/loaders/lottie/tvgLottieExpressions.cpp | 5 ++++- src/loaders/lottie/tvgLottieParser.cpp | 1 + src/loaders/lottie/tvgLottieProperty.h | 10 ++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/loaders/lottie/tvgLottieExpressions.cpp b/src/loaders/lottie/tvgLottieExpressions.cpp index 4b7e1177..a8494a49 100644 --- a/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/src/loaders/lottie/tvgLottieExpressions.cpp @@ -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); diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 3b32f472..782e0030 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -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; } diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index f7aea077..85720c8a 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -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>(frameNo, out, exp)) return out; } @@ -507,7 +509,7 @@ struct LottiePathSet : LottieProperty bool operator()(float frameNo, Array& cmds, Array& 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(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(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(frameNo, out, exp)) return out; }