diff src/Analyser.cpp @ 226:9bdff8d10a86

Fix #899 crash when loading new file
author Chris Cannam
date Mon, 10 Mar 2014 14:59:50 +0000
parents d323b5d41570
children ae0bf8dc5833
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);