# HG changeset patch # User Chris Cannam # Date 1466667980 -3600 # Node ID 85e49aa7fe7732e53f254f91aedfd077599366f9 # Parent 77564d4fff434cefaa64fcba9ad7a115e0a14375 Fix possible crash when scrolling to end diff -r 77564d4fff43 -r 85e49aa7fe77 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Mon Jun 20 12:00:32 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Thu Jun 23 08:46:20 2016 +0100 @@ -2293,27 +2293,29 @@ } } } + + if (!pixelPeakColumn.empty()) { + for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin(); + pi != peakfreqs.end(); ++pi) { + + int bin = pi->first; + double freq = pi->second; + + if (bin < minbin) continue; + if (bin > maxbin) break; + + double value = pixelPeakColumn[bin - minbin]; + + double y = v->getYForFrequency + (freq, displayMinFreq, displayMaxFreq, logarithmic); + + int iy = int(y + 0.5); + if (iy < 0 || iy >= h) continue; + + m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value)); + } + } - for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin(); - pi != peakfreqs.end(); ++pi) { - - int bin = pi->first; - double freq = pi->second; - - if (bin < minbin) continue; - if (bin > maxbin) break; - - double value = pixelPeakColumn[bin - minbin]; - - double y = v->getYForFrequency - (freq, displayMinFreq, displayMaxFreq, logarithmic); - - int iy = int(y + 0.5); - if (iy < 0 || iy >= h) continue; - - m_drawBuffer.setPixel(x, iy, getDisplayValue(v, value)); - } - if (haveTimeLimits) { if (columnCount >= minColumns) { auto t = chrono::steady_clock::now(); @@ -2560,10 +2562,12 @@ } } - for (int y = 0; y < h; ++y) { - m_drawBuffer.setPixel(x, - h-y-1, - getDisplayValue(v, pixelPeakColumn[y])); + if (!pixelPeakColumn.empty()) { + for (int y = 0; y < h; ++y) { + m_drawBuffer.setPixel(x, + h-y-1, + getDisplayValue(v, pixelPeakColumn[y])); + } } if (haveTimeLimits) {