libobs: Fix default negative int/float shader vals
If negative was specified it would not parse the negative sign and thus would not interpret that number as negative, and would cause shader/effect parsing to simply fail on the file.
This commit is contained in:
parent
cdb27ac06b
commit
e4305d147b
@ -718,19 +718,29 @@ static inline int ep_parse_param_assign_intfloat(struct effect_parser *ep,
|
||||
struct ep_param *param, bool is_float)
|
||||
{
|
||||
int code;
|
||||
bool is_negative = false;
|
||||
|
||||
if (!cf_next_valid_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&ep->cfp, "-")) {
|
||||
is_negative = true;
|
||||
|
||||
if (!cf_next_token(&ep->cfp))
|
||||
return PARSE_EOF;
|
||||
}
|
||||
|
||||
code = cf_token_is_type(&ep->cfp, CFTOKEN_NUM, "numeric value", ";");
|
||||
if (code != PARSE_SUCCESS)
|
||||
return code;
|
||||
|
||||
if (is_float) {
|
||||
float f = (float)strtod(ep->cfp.cur_token->str.array, NULL);
|
||||
if (is_negative) f = -f;
|
||||
da_push_back_array(param->default_val, &f, sizeof(float));
|
||||
} else {
|
||||
long l = strtol(ep->cfp.cur_token->str.array, NULL, 10);
|
||||
if (is_negative) l = -l;
|
||||
da_push_back_array(param->default_val, &l, sizeof(long));
|
||||
}
|
||||
|
||||
|
@ -472,19 +472,29 @@ static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
|
||||
struct shader_var *param, bool is_float)
|
||||
{
|
||||
int code;
|
||||
bool is_negative = false;
|
||||
|
||||
if (!cf_next_valid_token(&sp->cfp))
|
||||
return PARSE_EOF;
|
||||
|
||||
if (cf_token_is(&sp->cfp, "-")) {
|
||||
is_negative = true;
|
||||
|
||||
if (!cf_next_token(&sp->cfp))
|
||||
return PARSE_EOF;
|
||||
}
|
||||
|
||||
code = cf_token_is_type(&sp->cfp, CFTOKEN_NUM, "numeric value", ";");
|
||||
if (code != PARSE_SUCCESS)
|
||||
return code;
|
||||
|
||||
if (is_float) {
|
||||
float f = (float)strtod(sp->cfp.cur_token->str.array, NULL);
|
||||
if (is_negative) f = -f;
|
||||
da_push_back_array(param->default_val, &f, sizeof(float));
|
||||
} else {
|
||||
long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
|
||||
if (is_negative) l = -l;
|
||||
da_push_back_array(param->default_val, &l, sizeof(long));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user