Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1242:b10bd0611d16
Fix various "model deleted with no aboutToDelete notification" warnings (and one associated potential memory leak)
author | Chris Cannam |
---|---|
date | Wed, 22 Feb 2017 12:01:39 +0000 |
parents | a496986aa61b |
children | 9e1559b08f0d |
comparison
equal
deleted
inserted
replaced
1240:c2e923aa4015 | 1242:b10bd0611d16 |
---|---|
130 } | 130 } |
131 | 131 |
132 SpectrogramLayer::~SpectrogramLayer() | 132 SpectrogramLayer::~SpectrogramLayer() |
133 { | 133 { |
134 invalidateRenderers(); | 134 invalidateRenderers(); |
135 deleteDerivedModels(); | |
136 } | |
137 | |
138 void | |
139 SpectrogramLayer::deleteDerivedModels() | |
140 { | |
141 if (m_fftModel) m_fftModel->aboutToDelete(); | |
142 if (m_peakCache) m_peakCache->aboutToDelete(); | |
143 if (m_wholeCache) m_wholeCache->aboutToDelete(); | |
135 | 144 |
136 delete m_fftModel; | 145 delete m_fftModel; |
137 delete m_peakCache; | 146 delete m_peakCache; |
138 delete m_wholeCache; | 147 delete m_wholeCache; |
148 | |
149 m_fftModel = 0; | |
150 m_peakCache = 0; | |
151 m_wholeCache = 0; | |
139 } | 152 } |
140 | 153 |
141 pair<ColourScaleType, double> | 154 pair<ColourScaleType, double> |
142 SpectrogramLayer::convertToColourScale(int value) | 155 SpectrogramLayer::convertToColourScale(int value) |
143 { | 156 { |
1337 } | 1350 } |
1338 | 1351 |
1339 void | 1352 void |
1340 SpectrogramLayer::recreateFFTModel() | 1353 SpectrogramLayer::recreateFFTModel() |
1341 { | 1354 { |
1342 #ifdef DEBUG_SPECTROGRAM | 1355 SVDEBUG << "SpectrogramLayer::recreateFFTModel called" << endl; |
1343 cerr << "SpectrogramLayer::recreateFFTModel called" << endl; | |
1344 #endif | |
1345 | 1356 |
1346 if (!m_model || !m_model->isOK()) { | 1357 if (!m_model || !m_model->isOK()) { |
1347 emit sliceableModelReplaced(m_fftModel, 0); | 1358 emit sliceableModelReplaced(m_fftModel, 0); |
1348 delete m_fftModel; | 1359 deleteDerivedModels(); |
1349 delete m_peakCache; | |
1350 delete m_wholeCache; | |
1351 m_fftModel = 0; | |
1352 m_peakCache = 0; | |
1353 m_wholeCache = 0; | |
1354 return; | 1360 return; |
1355 } | 1361 } |
1356 | 1362 |
1357 FFTModel *oldModel = m_fftModel; | 1363 if (m_fftModel) m_fftModel->aboutToDelete(); |
1358 | 1364 |
1359 m_fftModel = new FFTModel(m_model, | 1365 if (m_peakCache) m_peakCache->aboutToDelete(); |
1360 m_channel, | |
1361 m_windowType, | |
1362 m_windowSize, | |
1363 getWindowIncrement(), | |
1364 getFFTSize()); | |
1365 | |
1366 delete m_peakCache; | 1366 delete m_peakCache; |
1367 m_peakCache = 0; | 1367 m_peakCache = 0; |
1368 | 1368 |
1369 if (m_wholeCache) m_wholeCache->aboutToDelete(); | |
1369 delete m_wholeCache; | 1370 delete m_wholeCache; |
1370 m_wholeCache = 0; | 1371 m_wholeCache = 0; |
1371 | 1372 |
1372 if (!m_fftModel->isOK()) { | 1373 FFTModel *newModel = new FFTModel(m_model, |
1374 m_channel, | |
1375 m_windowType, | |
1376 m_windowSize, | |
1377 getWindowIncrement(), | |
1378 getFFTSize()); | |
1379 | |
1380 if (!newModel->isOK()) { | |
1373 QMessageBox::critical | 1381 QMessageBox::critical |
1374 (0, tr("FFT cache failed"), | 1382 (0, tr("FFT cache failed"), |
1375 tr("Failed to create the FFT model for this spectrogram.\n" | 1383 tr("Failed to create the FFT model for this spectrogram.\n" |
1376 "There may be insufficient memory or disc space to continue.")); | 1384 "There may be insufficient memory or disc space to continue.")); |
1385 delete newModel; | |
1377 delete m_fftModel; | 1386 delete m_fftModel; |
1378 m_fftModel = 0; | 1387 m_fftModel = 0; |
1379 return; | 1388 return; |
1380 } | 1389 } |
1390 | |
1391 FFTModel *oldModel = m_fftModel; | |
1392 m_fftModel = newModel; | |
1381 | 1393 |
1382 if (canStoreWholeCache()) { // i.e. if enough memory | 1394 if (canStoreWholeCache()) { // i.e. if enough memory |
1383 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1); | 1395 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1); |
1384 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor); | 1396 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor); |
1385 } else { | 1397 } else { |
1386 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor); | 1398 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor); |
1387 } | 1399 } |
1388 | 1400 |
1389 emit sliceableModelReplaced(oldModel, m_fftModel); | 1401 emit sliceableModelReplaced(oldModel, m_fftModel); |
1390 | |
1391 delete oldModel; | 1402 delete oldModel; |
1392 } | 1403 } |
1393 | 1404 |
1394 bool | 1405 bool |
1395 SpectrogramLayer::canStoreWholeCache() const | 1406 SpectrogramLayer::canStoreWholeCache() const |