diff transform/FeatureExtractionModelTransformer.cpp @ 1755:fd7f127ecd89 by-id

Don't hold on to borrowed pointer around the loop - so as to be informed when it becomes obsolete
author Chris Cannam
date Fri, 05 Jul 2019 16:55:54 +0100
parents 6d09d68165a4
children 110f853c3149
line wrap: on
line diff
--- a/transform/FeatureExtractionModelTransformer.cpp	Fri Jul 05 16:55:27 2019 +0100
+++ b/transform/FeatureExtractionModelTransformer.cpp	Fri Jul 05 16:55:54 2019 +0100
@@ -648,17 +648,29 @@
     if (m_abandoned) return;
 
     ModelId inputId = getInputModel();
-    auto input = ModelById::getAs<DenseTimeValueModel>(inputId);
-    if (!input) {
-        abandon();
-        return;
-    }
 
-    sv_samplerate_t sampleRate = input->getSampleRate();
+    sv_samplerate_t sampleRate;
+    int channelCount;
+    sv_frame_t startFrame;
+    sv_frame_t endFrame;
+    
+    { // scope so as not to have this borrowed pointer retained around
+      // the edges of the process loop
+        auto input = ModelById::getAs<DenseTimeValueModel>(inputId);
+        if (!input) {
+            abandon();
+            return;
+        }
 
-    int channelCount = input->getChannelCount();
-    if ((int)m_plugin->getMaxChannelCount() < channelCount) {
-        channelCount = 1;
+        sampleRate = input->getSampleRate();
+
+        channelCount = input->getChannelCount();
+        if ((int)m_plugin->getMaxChannelCount() < channelCount) {
+            channelCount = 1;
+        }
+
+        startFrame = input->getStartFrame();
+        endFrame = input->getEndFrame();
     }
 
     float **buffers = new float*[channelCount];
@@ -696,9 +708,6 @@
         }
     }
 
-    sv_frame_t startFrame = input->getStartFrame();
-    sv_frame_t endFrame = input->getEndFrame();
-
     RealTime contextStartRT = primaryTransform.getStartTime();
     RealTime contextDurationRT = primaryTransform.getDuration();
 
@@ -761,6 +770,11 @@
                 ((((blockFrame - contextStart) / stepSize) * 99) /
                  (contextDuration / stepSize + 1));
 
+            if (!ModelById::get(inputId)) {
+                abandon();
+                return;
+            }
+
             // channelCount is either input->channelCount or 1
 
             if (frequencyDomain) {