Mercurial > hg > svgui
changeset 742:d7e8cefedbbc
Diagnostics and fix for peaks cache sizing (need +1 to avoid null cache)
author | Chris Cannam |
---|---|
date | Tue, 11 Mar 2014 17:29:02 +0000 |
parents | 88a16eed3338 |
children | b6dc57688c72 cdafb1a438e8 |
files | layer/Colour3DPlotLayer.cpp |
diffstat | 1 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Thu Mar 06 09:43:36 2014 +0000 +++ b/layer/Colour3DPlotLayer.cpp Tue Mar 11 17:29:02 2014 +0000 @@ -959,6 +959,7 @@ size_t cacheHeight = m_model->getHeight(); if (m_cache && (m_cache->height() != int(cacheHeight))) { + // height has changed: delete everything rather than resizing delete m_cache; delete m_peaksCache; m_cache = 0; @@ -966,6 +967,7 @@ } if (m_cache && (m_cache->width() != int(cacheWidth))) { + // width has changed and we have an existing cache: resize it QImage *newCache = new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight)); delete m_cache; @@ -973,7 +975,7 @@ if (m_peaksCache) { QImage *newPeaksCache = new QImage(m_peaksCache->copy - (0, 0, cacheWidth / m_peakResolution, cacheHeight)); + (0, 0, cacheWidth / m_peakResolution + 1, cacheHeight)); delete m_peaksCache; m_peaksCache = newPeaksCache; } @@ -998,6 +1000,9 @@ m_cacheValidEnd = 0; } +// cerr << "cache size = " << m_cache->width() << "x" << m_cache->height() +// << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; + if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT cerr << "Cache is valid in this region already" << endl; @@ -1124,6 +1129,12 @@ values = getColumn(c); + if (c >= m_cache->width()) { + cerr << "ERROR: column " << c << " >= cache width " + << m_cache->width() << endl; + continue; + } + for (size_t y = 0; y < cacheHeight; ++y) { float value = min; @@ -1152,7 +1163,11 @@ if (m_invertVertical) { m_cache->setPixel(c, cacheHeight - y - 1, pixel); } else { - m_cache->setPixel(c, y, pixel); + if (y >= m_cache->height()) { + cerr << "ERROR: row " << y << " >= cache height " << m_cache->height() << endl; + } else { + m_cache->setPixel(c, y, pixel); + } } } @@ -1160,11 +1175,23 @@ size_t notch = (c % m_peakResolution); if (notch == m_peakResolution-1 || c == fillEnd) { size_t pc = c / m_peakResolution; + if (pc >= m_peaksCache->width()) { + cerr << "ERROR: peak column " << pc + << " (from col " << c << ") >= peaks cache width " + << m_peaksCache->width() << endl; + continue; + } for (size_t y = 0; y < cacheHeight; ++y) { if (m_invertVertical) { m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]); } else { - m_peaksCache->setPixel(pc, y, peaks[y]); + if (y >= m_peaksCache->height()) { + cerr << "ERROR: row " << y + << " >= peaks cache height " + << m_peaksCache->height() << endl; + } else { + m_peaksCache->setPixel(pc, y, peaks[y]); + } } } for (int y = 0; y < cacheHeight; ++y) {