Commit 5e5ed3b1 authored by Martin Heistermann's avatar Martin Heistermann

Expose PropertyPtr use_count and use it to properly keep used properties during clear().

parent 15670d62
Pipeline #7414 passed with stage
in 3 minutes and 59 seconds
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {} explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {} explicit BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
BaseProperty& operator=(const BaseProperty& _cpy) = delete; BaseProperty& operator=(const BaseProperty& _cpy) = delete;
...@@ -87,6 +87,9 @@ public: ...@@ -87,6 +87,9 @@ public:
virtual const std::string typeNameWrapper() const = 0; virtual const std::string typeNameWrapper() const = 0;
/// return the PropertyPtr shared_ptr use count
virtual long use_count() const = 0;
protected: protected:
virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0; virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0;
......
...@@ -105,6 +105,8 @@ public: ...@@ -105,6 +105,8 @@ public:
virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); } virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }
virtual long use_count() const { return ptr::shared_ptr<PropT>::use_count(); }
protected: protected:
virtual void delete_multiple_entries(const std::vector<bool>& _tags); virtual void delete_multiple_entries(const std::vector<bool>& _tags);
......
...@@ -62,7 +62,7 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() { ...@@ -62,7 +62,7 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* remove it, since the resource manager is the * remove it, since the resource manager is the
* only one who stores the property. * only one who stores the property.
*/ */
if(resMan_ && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) { if(resMan_ && !persistent() && use_count() == 2) {
resMan_->release_property(HandleT(handle().idx())); resMan_->release_property(HandleT(handle().idx()));
} }
} }
......
...@@ -197,12 +197,18 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle& ...@@ -197,12 +197,18 @@ void ResourceManager::entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle&
template<class StdVecT> template<class StdVecT>
void ResourceManager::clearVec(StdVecT& _vec) { void ResourceManager::clearVec(StdVecT& _vec) {
StdVecT newVec;
for (auto prop: _vec) { for (auto prop: _vec) {
prop->setResMan(nullptr); if (prop->use_count() == 1) {
delete prop; // No-one else holds a PropertyPtr to this object.
prop->setResMan(nullptr);
delete prop;
} else {
newVec.push_back(prop);
}
} }
_vec.clear(); _vec = newVec;
updatePropHandles(_vec);
} }
template<class StdVecT> template<class StdVecT>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment