changeset 1348:01778052e663

Avoid blowing up when faced with min==max in parameter range
author Chris Cannam
date Mon, 01 Oct 2018 14:46:36 +0100
parents edfc38ade098
children 615eb28768ca 5ac1c323ac55
files widgets/PluginParameterBox.cpp
diffstat 1 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/PluginParameterBox.cpp	Mon Oct 01 14:37:58 2018 +0100
+++ b/widgets/PluginParameterBox.cpp	Mon Oct 01 14:46:36 2018 +0100
@@ -121,6 +121,10 @@
         if (!(hint & PortHint::Logarithmic)) {
             if (qtz > 0.0) {
                 imax = int(lrintf((max - min) / qtz));
+                if (imax <= imin) {
+                    imax = 100;
+                    qtz = (max - min) / 100.f;
+                }
             } else {
                 qtz = (max - min) / 100.f;
             }
@@ -181,15 +185,22 @@
 //            dial->setValue(lrintf((value - min) / qtz));
             dial->setFixedWidth(32);
             dial->setFixedHeight(32);
-            RangeMapper *rm = 0;
-            if (hint & PortHint::Logarithmic) {
-                rm = new LogRangeMapper(imin, imax, min, max, unit);
+            if (max == min || imax == imin) {
+                SVCERR << "WARNING: for parameter \"" << name
+                       << "\" of plugin \"" << m_plugin->getName()
+                       << "\": invalid range " << min << " -> " << max
+                       << " with quantize step " << qtz << endl;
             } else {
-                rm = new LinearRangeMapper(imin, imax, min, max, unit);
+                RangeMapper *rm = 0;
+                if (hint & PortHint::Logarithmic) {
+                    rm = new LogRangeMapper(imin, imax, min, max, unit);
+                } else {
+                    rm = new LinearRangeMapper(imin, imax, min, max, unit);
+                }
+                dial->setRangeMapper(rm);
+                dial->setDefaultValue(rm->getPositionForValue(deft));
+                dial->setValue(rm->getPositionForValue(value));
             }
-            dial->setRangeMapper(rm);
-            dial->setDefaultValue(rm->getPositionForValue(deft));
-            dial->setValue(rm->getPositionForValue(value));
             dial->setShowToolTip(true);
             connect(dial, SIGNAL(valueChanged(int)),
                     this, SLOT(dialChanged(int)));