# HG changeset patch # User Chris Cannam # Date 1554372943 -3600 # Node ID 901f37d320608feddcdd67ed4e1ac671db8159d0 # Parent 0e0947896fd3b2406983aca444ba98285c09528c Model deletion issues - the AlignmentModel doesn't actually need to know about the input aggregate model; the document should own it instead diff -r 0e0947896fd3 -r 901f37d32060 data/model/AggregateWaveModel.cpp --- a/data/model/AggregateWaveModel.cpp Wed Feb 27 12:31:12 2019 +0000 +++ b/data/model/AggregateWaveModel.cpp Thu Apr 04 11:15:43 2019 +0100 @@ -46,6 +46,7 @@ AggregateWaveModel::~AggregateWaveModel() { + SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl; } void @@ -61,7 +62,7 @@ bool AggregateWaveModel::isOK() const { - if (m_invalidated) { + if (m_invalidated || m_components.empty()) { return false; } for (ChannelSpecList::const_iterator i = m_components.begin(); @@ -120,13 +121,15 @@ sv_samplerate_t AggregateWaveModel::getSampleRate() const { - if (m_components.empty()) return 0; + if (m_invalidated || m_components.empty()) return 0; return m_components.begin()->model->getSampleRate(); } floatvec_t AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const { + if (m_invalidated || m_components.empty()) return {}; + int ch0 = channel, ch1 = channel; if (channel == -1) { ch0 = 0; diff -r 0e0947896fd3 -r 901f37d32060 data/model/AlignmentModel.cpp --- a/data/model/AlignmentModel.cpp Wed Feb 27 12:31:12 2019 +0000 +++ b/data/model/AlignmentModel.cpp Thu Apr 04 11:15:43 2019 +0100 @@ -21,11 +21,9 @@ AlignmentModel::AlignmentModel(Model *reference, Model *aligned, - Model *inputModel, SparseTimeValueModel *path) : m_reference(reference), m_aligned(aligned), - m_inputModel(inputModel), m_rawPath(path), m_path(nullptr), m_reversePath(nullptr), @@ -54,9 +52,6 @@ AlignmentModel::~AlignmentModel() { - if (m_inputModel) m_inputModel->aboutToDelete(); - delete m_inputModel; - if (m_rawPath) m_rawPath->aboutToDelete(); delete m_rawPath; @@ -212,9 +207,6 @@ constructPath(); constructReversePath(); - if (m_inputModel) m_inputModel->aboutToDelete(); - delete m_inputModel; - m_inputModel = nullptr; } } diff -r 0e0947896fd3 -r 901f37d32060 data/model/AlignmentModel.h --- a/data/model/AlignmentModel.h Wed Feb 27 12:31:12 2019 +0000 +++ b/data/model/AlignmentModel.h Thu Apr 04 11:15:43 2019 +0100 @@ -32,8 +32,7 @@ public: AlignmentModel(Model *reference, Model *aligned, - Model *inputModel, // probably an AggregateWaveModel; may be null; I take ownership - SparseTimeValueModel *path); // I take ownership + SparseTimeValueModel *path); ~AlignmentModel(); bool isOK() const override; @@ -72,8 +71,6 @@ Model *m_reference; // I don't own this Model *m_aligned; // I don't own this - Model *m_inputModel; // I own this - SparseTimeValueModel *m_rawPath; // I own this mutable PathModel *m_path; // I own this mutable PathModel *m_reversePath; // I own this diff -r 0e0947896fd3 -r 901f37d32060 data/model/FFTModel.cpp --- a/data/model/FFTModel.cpp Wed Feb 27 12:31:12 2019 +0000 +++ b/data/model/FFTModel.cpp Thu Apr 04 11:15:43 2019 +0100 @@ -61,9 +61,12 @@ m_fft.initFloat(); - connect(model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); + connect(model, SIGNAL(modelChanged()), + this, SIGNAL(modelChanged())); connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); + connect(model, SIGNAL(aboutToBeDeleted()), + this, SLOT(sourceModelAboutToBeDeleted())); } FFTModel::~FFTModel() @@ -273,6 +276,8 @@ FFTModel::getSourceDataUncached(pair range) const { Profiler profiler("FFTModel::getSourceDataUncached"); + + if (!m_model) return {}; decltype(range.first) pfx = 0; if (range.first < 0) {