# HG changeset patch # User Chris Cannam # Date 1538401596 -3600 # Node ID 01778052e6635e4d7644c65a2c049c074d390e28 # Parent edfc38ade0988b46bae548f28fdc6977d45ccf6d Avoid blowing up when faced with min==max in parameter range diff -r edfc38ade098 -r 01778052e663 widgets/PluginParameterBox.cpp --- 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)));