# HG changeset patch # User Chris Cannam # Date 1477650756 -3600 # Node ID a83541a1f1003244e058a86a7ba0cde8bc7ed409 # Parent fe391a7b837649394839e760036c07d73f273233 Ensure plugin is deleted in same thread that created and used it diff -r fe391a7b8376 -r a83541a1f100 transform/FeatureExtractionModelTransformer.cpp --- a/transform/FeatureExtractionModelTransformer.cpp Fri Oct 28 11:08:17 2016 +0100 +++ b/transform/FeatureExtractionModelTransformer.cpp Fri Oct 28 11:32:36 2016 +0100 @@ -47,8 +47,6 @@ m_haveOutputs(false) { SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; - -// initialise(); } FeatureExtractionModelTransformer::FeatureExtractionModelTransformer(Input in, @@ -62,8 +60,6 @@ } else { SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: " << transforms.size() << " transform(s), first has plugin " << m_transforms.begin()->getPluginIdentifier() << ", outputName " << m_transforms.begin()->getOutput() << endl; } - -// initialise(); } static bool @@ -77,6 +73,10 @@ bool FeatureExtractionModelTransformer::initialise() { + // This is (now) called from the run thread. The plugin is + // constructed, initialised, used, and destroyed all from a single + // thread. + // All transforms must use the same plugin, parameters, and // inputs: they can differ only in choice of plugin output. So we // initialise based purely on the first transform in the list (but @@ -235,6 +235,18 @@ } void +FeatureExtractionModelTransformer::deinitialise() +{ + cerr << "deleting plugin for transform in thread " + << QThread::currentThreadId() << endl; + + delete m_plugin; + for (int j = 0; j < (int)m_descriptors.size(); ++j) { + delete m_descriptors[j]; + } +} + +void FeatureExtractionModelTransformer::createOutputModels(int n) { DenseTimeValueModel *input = getConformingInput(); @@ -502,11 +514,9 @@ FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() { -// SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; - delete m_plugin; - for (int j = 0; j < (int)m_descriptors.size(); ++j) { - delete m_descriptors[j]; - } + // Parent class dtor set the abandoned flag and waited for the run + // thread to exit; the run thread owns the plugin, and should have + // destroyed it before exiting (via a call to deinitialise) } FeatureExtractionModelTransformer::Models @@ -781,6 +791,8 @@ delete[] buffers[ch]; } delete[] buffers; + + deinitialise(); } void diff -r fe391a7b8376 -r a83541a1f100 transform/FeatureExtractionModelTransformer.h --- a/transform/FeatureExtractionModelTransformer.h Fri Oct 28 11:08:17 2016 +0100 +++ b/transform/FeatureExtractionModelTransformer.h Fri Oct 28 11:32:36 2016 +0100 @@ -52,6 +52,7 @@ protected: bool initialise(); + void deinitialise(); virtual void run();