Mercurial > hg > svapp
changeset 676:0d4236961c97
Ensure that AggregateModels are actually deleted on release despite not being in model list (ugh, this is ugly)
author | Chris Cannam |
---|---|
date | Tue, 11 Jun 2019 13:39:17 +0100 |
parents | b375fdbb74bc |
children | 4d26b66931f8 |
files | framework/Document.cpp |
diffstat | 1 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/framework/Document.cpp Fri May 17 13:49:25 2019 +0100 +++ b/framework/Document.cpp Tue Jun 11 13:39:17 2019 +0100 @@ -804,10 +804,12 @@ } bool toDelete = false; + bool isInModelList = false; // should become true for any "normal" model ModelList::iterator mitr = findModelInList(model); - + if (mitr != m_models.end()) { + if (mitr->refcount == 0) { SVCERR << "WARNING: Document::releaseModel: model " << model << " reference count is zero already!" << endl; @@ -819,6 +821,8 @@ toDelete = true; } } + isInModelList = true; + } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) { #ifdef DEBUG_DOCUMENT SVDEBUG << "Document::releaseModel: is an aggregate model" << endl; @@ -848,16 +852,26 @@ << "their source fields appropriately" << endl; } - deleteModelFromList(model); + if (isInModelList) { + deleteModelFromList(model); #ifdef DEBUG_DOCUMENT - SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; - SVDEBUG << "Models now: "; - for (const auto &r: m_models) { - SVDEBUG << r.model << " "; - } - SVDEBUG << endl; + SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; + SVDEBUG << "Models now: "; + for (const auto &r: m_models) { + SVDEBUG << r.model << " "; + } + SVDEBUG << endl; #endif + } else { + model->aboutToDelete(); + emit modelAboutToBeDeleted(model); + delete model; + +#ifdef DEBUG_DOCUMENT + SVDEBUG << "Document::releaseModel: Deleted awkward model " << model << endl; +#endif + } } }