changeset 1784:4eac4bf35b45

More graceful handling of failure to construct FFT models in the case where the source model has already been deleted before this occurs
author Chris Cannam
date Tue, 17 Sep 2019 11:21:33 +0100
parents cf3eb6252f42
children 894c2a780444 7fc6256af2d2
files data/model/FFTModel.cpp data/model/FFTModel.h transform/FeatureExtractionModelTransformer.cpp
diffstat 3 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/FFTModel.cpp	Tue Sep 17 10:42:55 2019 +0100
+++ b/data/model/FFTModel.cpp	Tue Sep 17 11:21:33 2019 +0100
@@ -71,6 +71,8 @@
                 this, SIGNAL(modelChanged(ModelId)));
         connect(model.get(), SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)),
                 this, SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)));
+    } else {
+        m_error = QString("Model #%1 is not available").arg(m_model.untyped);
     }
 }
 
@@ -82,7 +84,15 @@
 FFTModel::isOK() const
 {
     auto model = ModelById::getAs<DenseTimeValueModel>(m_model);
-    return (model && model->isOK());
+    if (!model) {
+        m_error = QString("Model #%1 is not available").arg(m_model.untyped);
+        return false;
+    }
+    if (!model->isOK()) {
+        m_error = QString("Model #%1 is not OK").arg(m_model.untyped);
+        return false;
+    }
+    return true;
 }
 
 int
--- a/data/model/FFTModel.h	Tue Sep 17 10:42:55 2019 +0100
+++ b/data/model/FFTModel.h	Tue Sep 17 11:21:33 2019 +0100
@@ -78,7 +78,7 @@
     QString getBinName(int n) const override;
     bool shouldUseLogValueScale() const override { return true; }
     int getCompletion() const override;
-    virtual QString getError() const { return ""; } //!!!???
+    virtual QString getError() const { return m_error; }
     virtual sv_frame_t getFillExtent() const { return getEndFrame(); }
     QString toDelimitedDataString(QString, DataExportOptions,
                                   sv_frame_t, sv_frame_t) const override {
@@ -152,6 +152,7 @@
     Window<float> m_windower;
     mutable breakfastquay::FFT m_fft;
     double m_maximumFrequency;
+    mutable QString m_error;
     
     int getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate,
                               int bin, double &dist) const;
--- a/transform/FeatureExtractionModelTransformer.cpp	Tue Sep 17 10:42:55 2019 +0100
+++ b/transform/FeatureExtractionModelTransformer.cpp	Tue Sep 17 11:21:33 2019 +0100
@@ -643,7 +643,7 @@
     while (!ready && !m_abandoned) {
         { // scope so as to release input shared_ptr before sleeping
             auto input = ModelById::getAs<DenseTimeValueModel>(inputId);
-            if (!input) {
+            if (!input || !input->isOK()) {
                 abandon();
                 return;
             }
@@ -717,9 +717,13 @@
                 for (int j = 0; in_range_for(m_outputNos, j); ++j) {
                     setCompletion(j, 100);
                 }
-                //!!! need a better way to handle this -- previously we were using a QMessageBox but that isn't an appropriate thing to do here either
                 SVDEBUG << "FeatureExtractionModelTransformer::run: Failed to create FFT model for input model " << inputId << ": " << err << endl;
-                throw AllocationFailed("Failed to create the FFT model for this feature extraction model transformer: error is: " + err);
+                m_message = "Failed to create the FFT model for this feature extraction model transformer: error is: " + err;
+                for (int cch = 0; cch < ch; ++cch) {
+                    delete fftModels[cch];
+                }
+                abandon();
+                return;
             }
             fftModels.push_back(model);
         }