changeset 226:9bdff8d10a86

Fix #899 crash when loading new file
author Chris Cannam
date Mon, 10 Mar 2014 14:59:50 +0000
parents dd97a58277ea
children ae0bf8dc5833
files src/Analyser.cpp src/Analyser.h src/MainWindow.cpp
diffstat 3 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Analyser.cpp	Mon Mar 10 14:51:59 2014 +0000
+++ b/src/Analyser.cpp	Mon Mar 10 14:59:50 2014 +0000
@@ -106,6 +106,16 @@
     return warning;
 }
 
+void
+Analyser::fileClosed()
+{
+    cerr << "Analyser::fileClosed" << endl;
+    m_layers.clear();
+    m_reAnalysisCandidates.clear();
+    m_currentCandidate = -1;
+    m_reAnalysingSelection = Selection();
+}
+
 QString
 Analyser::addVisualisations()
 {
@@ -359,6 +369,21 @@
     //!!! how do we know these came from the right selection? user
     //!!! might have made another one since this request was issued
 
+    if (m_reAnalysingSelection == Selection()) {
+        // We don't want these (actually, as above, this should check
+        // that the selection is the same as the one requested -- but
+        // all we're doing here is checking that the selection exists
+        // at all, so hasn't been cleared or the document deleted or
+        // whatever)
+        for (int i = 0; i < (int)primary.size(); ++i) {
+            m_document->deleteLayer(primary[i]);
+        }
+        for (int i = 0; i < (int)additional.size(); ++i) {
+            m_document->deleteLayer(additional[i]);
+        }
+        return;
+    }
+
     CommandHistory::getInstance()->startCompoundOperation
         (tr("Re-Analyse Selection"), true);
 
--- a/src/Analyser.h	Mon Mar 10 14:51:59 2014 +0000
+++ b/src/Analyser.h	Mon Mar 10 14:59:50 2014 +0000
@@ -45,6 +45,9 @@
     // Process new main model, add derived layers; return "" on success or error string on failure
     QString newFileLoaded(Document *newDocument, WaveFileModel *model,
                           PaneStack *paneStack, Pane *pane);
+
+    // Discard any layers etc associated with the current document
+    void fileClosed();
 		       
     void setIntelligentActions(bool);
 
--- a/src/MainWindow.cpp	Mon Mar 10 14:51:59 2014 +0000
+++ b/src/MainWindow.cpp	Mon Mar 10 14:59:50 2014 +0000
@@ -1230,6 +1230,8 @@
 {
     if (!checkSaveModified()) return;
 
+    m_analyser->fileClosed();
+
     while (m_paneStack->getPaneCount() > 0) {
 
         Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);