Mercurial > hg > svapp
comparison framework/Document.cpp @ 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 | ae7584dbd668 |
children | 1f18e0f64af8 |
comparison
equal
deleted
inserted
replaced
674:b375fdbb74bc | 676:0d4236961c97 |
---|---|
802 if (model == m_mainModel) { | 802 if (model == m_mainModel) { |
803 return; | 803 return; |
804 } | 804 } |
805 | 805 |
806 bool toDelete = false; | 806 bool toDelete = false; |
807 bool isInModelList = false; // should become true for any "normal" model | |
807 | 808 |
808 ModelList::iterator mitr = findModelInList(model); | 809 ModelList::iterator mitr = findModelInList(model); |
809 | 810 |
810 if (mitr != m_models.end()) { | 811 if (mitr != m_models.end()) { |
812 | |
811 if (mitr->refcount == 0) { | 813 if (mitr->refcount == 0) { |
812 SVCERR << "WARNING: Document::releaseModel: model " << model | 814 SVCERR << "WARNING: Document::releaseModel: model " << model |
813 << " reference count is zero already!" << endl; | 815 << " reference count is zero already!" << endl; |
814 } else { | 816 } else { |
815 #ifdef DEBUG_DOCUMENT | 817 #ifdef DEBUG_DOCUMENT |
817 #endif | 819 #endif |
818 if (--mitr->refcount == 0) { | 820 if (--mitr->refcount == 0) { |
819 toDelete = true; | 821 toDelete = true; |
820 } | 822 } |
821 } | 823 } |
824 isInModelList = true; | |
825 | |
822 } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) { | 826 } else if (m_aggregateModels.find(model) != m_aggregateModels.end()) { |
823 #ifdef DEBUG_DOCUMENT | 827 #ifdef DEBUG_DOCUMENT |
824 SVDEBUG << "Document::releaseModel: is an aggregate model" << endl; | 828 SVDEBUG << "Document::releaseModel: is an aggregate model" << endl; |
825 #endif | 829 #endif |
826 toDelete = true; | 830 toDelete = true; |
846 << model << " even though it is source for " | 850 << model << " even though it is source for " |
847 << sourceCount << " other derived model(s) -- resetting " | 851 << sourceCount << " other derived model(s) -- resetting " |
848 << "their source fields appropriately" << endl; | 852 << "their source fields appropriately" << endl; |
849 } | 853 } |
850 | 854 |
851 deleteModelFromList(model); | 855 if (isInModelList) { |
852 | 856 deleteModelFromList(model); |
853 #ifdef DEBUG_DOCUMENT | 857 |
854 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; | 858 #ifdef DEBUG_DOCUMENT |
855 SVDEBUG << "Models now: "; | 859 SVDEBUG << "Document::releaseModel: Deleted model " << model << endl; |
856 for (const auto &r: m_models) { | 860 SVDEBUG << "Models now: "; |
857 SVDEBUG << r.model << " "; | 861 for (const auto &r: m_models) { |
858 } | 862 SVDEBUG << r.model << " "; |
859 SVDEBUG << endl; | 863 } |
860 #endif | 864 SVDEBUG << endl; |
865 #endif | |
866 } else { | |
867 model->aboutToDelete(); | |
868 emit modelAboutToBeDeleted(model); | |
869 delete model; | |
870 | |
871 #ifdef DEBUG_DOCUMENT | |
872 SVDEBUG << "Document::releaseModel: Deleted awkward model " << model << endl; | |
873 #endif | |
874 } | |
861 } | 875 } |
862 } | 876 } |
863 | 877 |
864 void | 878 void |
865 Document::deleteLayer(Layer *layer, bool force) | 879 Document::deleteLayer(Layer *layer, bool force) |