Browse Source

Silently fail is user enters a NAN expression in parameter field.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
4734f13ba8
2 changed files with 14 additions and 1 deletions
  1. +4
    -1
      src/Quantity.cpp
  2. +10
    -0
      src/engine/ParamQuantity.cpp

+ 4
- 1
src/Quantity.cpp View File

@@ -33,7 +33,7 @@ std::string Quantity::getDisplayValueString() {
void Quantity::setDisplayValueString(std::string s) {
static const double inf = INFINITY;
static te_variable vars[] = {
{"inf", &inf},
{"inf", &inf, TE_VARIABLE, NULL},
};
te_expr* expr = te_compile(s.c_str(), vars, LENGTHOF(vars), NULL);
if (!expr)
@@ -41,6 +41,9 @@ void Quantity::setDisplayValueString(std::string s) {

double result = te_eval(expr);
te_free(expr);
if (std::isnan(result))
return;

setDisplayValue(result);
}



+ 10
- 0
src/engine/ParamQuantity.cpp View File

@@ -80,11 +80,17 @@ float ParamQuantity::getDisplayValue() {
void ParamQuantity::setDisplayValue(float displayValue) {
if (!module)
return;

// Handle displayOffset
float v = displayValue - displayOffset;

// Handle displayMultiplier
if (displayMultiplier == 0.f)
v = 0.f;
else
v /= displayMultiplier;

// Handle displayBase
if (displayBase == 0.f) {
// Linear
// v is unchanged
@@ -97,6 +103,10 @@ void ParamQuantity::setDisplayValue(float displayValue) {
// Exponential
v = std::log(v) / std::log(displayBase);
}

if (std::isnan(v))
return;

setValue(v);
}



Loading…
Cancel
Save