lottie/expressions: revised exception handlings

This commit is contained in:
Hermet Park 2024-08-06 13:52:10 +09:00
parent 33d7425294
commit f7221f7f89
4 changed files with 11 additions and 24 deletions

View file

@ -1326,7 +1326,7 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp)
auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS);
if (jerry_value_is_exception(eval) || jerry_value_is_undefined(eval)) {
exp->enabled = false; // The feature is experimental, it will be forcefully turned off if it's incompatible.
TVGERR("LOTTIE", "Failed to dispatch the expressions!");
return jerry_undefined();
}

View file

@ -42,14 +42,12 @@ public:
bool result(float frameNo, NumType& out, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (jerry_value_is_number(bm_rt)) {
out = (NumType) jerry_value_as_number(bm_rt);
} else if (auto prop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
out = (*prop)(frameNo);
} else {
TVGERR("LOTTIE", "Failed dispatching a Value!");
return false;
}
jerry_value_free(bm_rt);
return true;
@ -59,6 +57,7 @@ public:
bool result(float frameNo, Point& out, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (jerry_value_is_object(bm_rt)) {
if (auto prop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
@ -71,9 +70,6 @@ public:
jerry_value_free(x);
jerry_value_free(y);
}
} else {
TVGERR("LOTTIE", "Failed dispatching Point!");
return false;
}
jerry_value_free(bm_rt);
return true;
@ -83,12 +79,10 @@ public:
bool result(float frameNo, RGB24& out, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (auto color = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
out = (*color)(frameNo);
} else {
TVGERR("LOTTIE", "Failed dispatching Color!");
return false;
}
jerry_value_free(bm_rt);
return true;
@ -98,12 +92,10 @@ public:
bool result(float frameNo, Fill* fill, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (auto colorStop = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*colorStop)(frameNo, fill, this);
} else {
TVGERR("LOTTIE", "Failed dispatching ColorStop!");
return false;
}
jerry_value_free(bm_rt);
return true;
@ -113,13 +105,11 @@ public:
bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, float roundness, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (auto pathset = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*pathset)(frameNo, cmds, pts, transform, roundness);
} else {
TVGERR("LOTTIE", "Failed dispatching PathSet!");
return false;
}
}
jerry_value_free(bm_rt);
return true;
}

View file

@ -44,7 +44,6 @@ static LottieExpression* _expression(char* code, LottieComposition* comp, Lottie
inst->layer = layer;
inst->object = object;
inst->property = property;
inst->enabled = true;
return inst;
}

View file

@ -199,8 +199,6 @@ struct LottieExpression
LottieObject* object;
LottieProperty* property;
bool enabled;
struct {
uint32_t key = 0; //the keyframe number repeating to
float in = FLT_MAX; //looping duration in frame number
@ -460,7 +458,7 @@ struct LottieGenericProperty : LottieProperty
T operator()(float frameNo, LottieExpressions* exps)
{
if (exps && (exp && exp->enabled)) {
if (exps && exp) {
T out{};
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottieGenericProperty<T>>(frameNo, out, exp)) return out;
@ -605,7 +603,7 @@ struct LottiePathSet : LottieProperty
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, float roundness, LottieExpressions* exps)
{
if (exps && (exp && exp->enabled)) {
if (exps && exp) {
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, exp)) return true;
}
@ -686,7 +684,7 @@ struct LottieColorStop : LottieProperty
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps)
{
if (exps && (exp && exp->enabled)) {
if (exps && exp) {
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottieColorStop>(frameNo, fill, exp)) return Result::Success;
}
@ -818,7 +816,7 @@ struct LottiePosition : LottieProperty
Point operator()(float frameNo, LottieExpressions* exps)
{
Point out{};
if (exps && (exp && exp->enabled)) {
if (exps && exp) {
if (exp->loop.mode != LottieExpression::LoopMode::None) frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottiePosition>(frameNo, out, exp)) return out;
}