From 6fd0c03ce32568f8bc91c1041fc169cc7622248f Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 18 May 2021 22:14:41 +0200 Subject: [PATCH 01/14] Destroy material when a mesh is deleted Signed-off-by: ahcorde --- include/ignition/rendering/Scene.hh | 5 +++++ include/ignition/rendering/base/BaseScene.hh | 3 +++ .../ignition/rendering/ogre/OgreMeshFactory.hh | 4 ++++ ogre/include/ignition/rendering/ogre/OgreScene.hh | 2 ++ ogre/src/OgreMaterial.cc | 6 ++++++ ogre/src/OgreMesh.cc | 4 ++++ ogre/src/OgreMeshFactory.cc | 14 ++++++++++++++ ogre/src/OgreScene.cc | 6 ++++++ .../ignition/rendering/ogre2/Ogre2MeshFactory.hh | 3 +++ .../include/ignition/rendering/ogre2/Ogre2Scene.hh | 3 +++ ogre2/src/Ogre2Material.cc | 7 +++++++ ogre2/src/Ogre2MeshFactory.cc | 13 +++++++++++++ ogre2/src/Ogre2Scene.cc | 6 ++++++ src/base/BaseScene.cc | 4 +++- 14 files changed, 79 insertions(+), 1 deletion(-) diff --git a/include/ignition/rendering/Scene.hh b/include/ignition/rendering/Scene.hh index b61404580..bfbfc9fd8 100644 --- a/include/ignition/rendering/Scene.hh +++ b/include/ignition/rendering/Scene.hh @@ -1028,6 +1028,11 @@ namespace ignition /// use of this scene after its destruction will result in undefined /// behavior. public: virtual void Destroy() = 0; + + /// \brief When a mesh is loaded some material are cached in memory, then + /// these materials are copied to the meshes. The method allows to remove + /// this cache. + public: virtual void ClearMaterialsCache() = 0; }; } } diff --git a/include/ignition/rendering/base/BaseScene.hh b/include/ignition/rendering/base/BaseScene.hh index 31670265b..b2ada1333 100644 --- a/include/ignition/rendering/base/BaseScene.hh +++ b/include/ignition/rendering/base/BaseScene.hh @@ -664,6 +664,9 @@ namespace ignition private: virtual void CreateMaterials(); + // Documentation inherited. + public: virtual void ClearMaterialsCache() = 0; + /// \brief Helper function to recursively destory nodes while checking /// for loops. /// \param[in] _node Node to be destroyed diff --git a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh index ceecd1916..f27db716b 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh @@ -56,7 +56,11 @@ namespace ignition protected: virtual bool Validate(const MeshDescriptor &_desc); + public: void ClearMaterialsCache(); + protected: OgreScenePtr scene; + + protected: std::vector materialCache; }; class IGNITION_RENDERING_OGRE_VISIBLE OgreSubMeshStoreFactory diff --git a/ogre/include/ignition/rendering/ogre/OgreScene.hh b/ogre/include/ignition/rendering/ogre/OgreScene.hh index 11145b2ac..1f57d20c5 100644 --- a/ogre/include/ignition/rendering/ogre/OgreScene.hh +++ b/ogre/include/ignition/rendering/ogre/OgreScene.hh @@ -200,6 +200,8 @@ namespace ignition protected: virtual MaterialMapPtr Materials() const override; + public: virtual void ClearMaterialsCache() override; + private: void CreateContext(); private: void CreateRootVisual(); diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index 7bb90d0c4..1fffd3dab 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -49,6 +49,12 @@ void OgreMaterial::Destroy() #if OGRE_VERSION_LT_1_10_1 if (!this->ogreMaterial.isNull()) { + Ogre::TextureManager &texManager = Ogre::TextureManager::getSingleton(); + + auto indexUnitStateToRemove = this->ogrePass->getTextureUnitStateIndex(this->ogreTexState); + this->ogrePass->removeTextureUnitState(indexUnitStateToRemove); + + texManager.remove(this->textureName); matManager.remove(this->ogreMaterial->getName()); this->ogreMaterial.setNull(); } diff --git a/ogre/src/OgreMesh.cc b/ogre/src/OgreMesh.cc index 764262636..a6aac4c49 100644 --- a/ogre/src/OgreMesh.cc +++ b/ogre/src/OgreMesh.cc @@ -58,6 +58,7 @@ void OgreMesh::Destroy() auto ogreScene = std::dynamic_pointer_cast(this->Scene()); + Ogre::MeshManager::getSingleton().remove(this->Name()); ogreScene->OgreSceneManager()->destroyEntity(this->ogreEntity); this->ogreEntity = nullptr; } @@ -284,6 +285,9 @@ Ogre::SubEntity *OgreSubMesh::OgreSubEntity() const ////////////////////////////////////////////////// void OgreSubMesh::Destroy() { + Ogre::MeshManager::getSingleton().remove(this->Name()); + Ogre::MaterialManager::getSingleton().remove( + this->ogreSubEntity->getMaterialName()); OgreRTShaderSystem::Instance()->DetachEntity(this); BaseSubMesh::Destroy(); diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index 55b31f669..058c7306b 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -106,6 +106,18 @@ bool OgreMeshFactory::IsLoaded(const MeshDescriptor &_desc) return Ogre::MeshManager::getSingleton().resourceExists(name); } +////////////////////////////////////////////////// +void OgreMeshFactory::ClearMaterialsCache() +{ + for (auto mat : this->materialCache) + { + std::string matName = mat->Name(); + mat->Destroy(); + this->scene->UnregisterMaterial(matName); + } + this->materialCache.clear(); +} + ////////////////////////////////////////////////// bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc) { @@ -405,6 +417,8 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc) } ogreSubMesh->setMaterialName(mat->Name()); + materialCache.push_back(mat); + // Unlock vBuf->unlock(); iBuf->unlock(); diff --git a/ogre/src/OgreScene.cc b/ogre/src/OgreScene.cc index 7fe8c4e44..f449ac1d5 100644 --- a/ogre/src/OgreScene.cc +++ b/ogre/src/OgreScene.cc @@ -345,6 +345,12 @@ VisualStorePtr OgreScene::Visuals() const return this->visuals; } +////////////////////////////////////////////////// +void OgreScene::ClearMaterialsCache() +{ + this->meshFactory->ClearMaterialsCache(); +} + ////////////////////////////////////////////////// MaterialMapPtr OgreScene::Materials() const { diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh index e98a253b1..e2b656d2a 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh @@ -94,6 +94,9 @@ namespace ignition /// \brief Pointer to the scene object protected: Ogre2ScenePtr scene; + /// \brief Remove internal material cache + public: void ClearMaterialsCache(); + /// \brief Pointer to private data class private: std::unique_ptr dataPtr; }; diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh index 7193708f4..ab4f1d16d 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh @@ -298,6 +298,9 @@ namespace ignition /// \brief Create the vaiours storage objects private: void CreateStores(); + // Documentation inherited + public: virtual void ClearMaterialsCache() override; + /// \brief Create a shared pointer to self private: Ogre2ScenePtr SharedThis(); diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index f72d2b9e0..a721e6b11 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -70,6 +70,13 @@ void Ogre2Material::Destroy() if (!this->ogreDatablock) return; + if (!this->textureName.empty()) + { + Ogre::HlmsTextureManager *hlmsTextureManager = + this->ogreHlmsPbs->getHlmsManager()->getTextureManager(); + hlmsTextureManager->destroyTexture(this->textureName); + } + this->ogreHlmsPbs->destroyDatablock(this->ogreDatablockId); this->ogreDatablock = nullptr; diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index 0d21f5eac..826d560a8 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -58,6 +58,7 @@ /// \brief Private data for the Ogre2MeshFactory class class ignition::rendering::Ogre2MeshFactoryPrivate { + public: std::vector materialCache; }; /// \brief Private data for the Ogre2SubMeshStoreFactory class @@ -88,6 +89,17 @@ void Ogre2MeshFactory::Clear() this->ogreMeshes.clear(); } +void Ogre2MeshFactory::ClearMaterialsCache() +{ + for (auto mat : this->dataPtr->materialCache) + { + std::string matName = mat->Name(); + mat->Destroy(); + this->scene->UnregisterMaterial(matName); + } + this->dataPtr->materialCache.clear(); +} + ////////////////////////////////////////////////// Ogre2MeshPtr Ogre2MeshFactory::Create(const MeshDescriptor &_desc) { @@ -455,6 +467,7 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc) mat->CopyFrom(defaultMat); } ogreSubMesh->setMaterialName(mat->Name()); + this->dataPtr->materialCache.push_back(mat); } math::Vector3d max = _desc.mesh->Max(); diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index 580734ef5..08151e3fa 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -116,6 +116,12 @@ math::Color Ogre2Scene::AmbientLight() const return Ogre2Conversions::Convert(ogreColor); } +////////////////////////////////////////////////// +void Ogre2Scene::ClearMaterialsCache() +{ + this->meshFactory->ClearMaterialsCache(); +} + ////////////////////////////////////////////////// void Ogre2Scene::SetAmbientLight(const math::Color &_color) { diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index 76094afb8..f41422111 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -1048,7 +1048,9 @@ MeshPtr BaseScene::CreateMesh(const MeshDescriptor &_desc) unsigned int objId = this->CreateObjectId(); std::string objName = this->CreateObjectName(objId, "Mesh-" + meshName); - return this->CreateMeshImpl(objId, objName, _desc); + MeshPtr mesh = this->CreateMeshImpl(objId, objName, _desc); + this->ClearMaterialsCache(); + return mesh; } ////////////////////////////////////////////////// From ba78813a704acf422d3cd9095d95d995d6a60022 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 19 May 2021 21:59:09 +0200 Subject: [PATCH 02/14] Fixed issue Signed-off-by: ahcorde --- ogre/src/OgreMesh.cc | 2 +- ogre/src/OgreMeshFactory.cc | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ogre/src/OgreMesh.cc b/ogre/src/OgreMesh.cc index a6aac4c49..0a431f0b8 100644 --- a/ogre/src/OgreMesh.cc +++ b/ogre/src/OgreMesh.cc @@ -58,7 +58,7 @@ void OgreMesh::Destroy() auto ogreScene = std::dynamic_pointer_cast(this->Scene()); - Ogre::MeshManager::getSingleton().remove(this->Name()); + Ogre::MeshManager::getSingleton().remove(this->ogreEntity->getMesh()->getHandle()); ogreScene->OgreSceneManager()->destroyEntity(this->ogreEntity); this->ogreEntity = nullptr; } diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index 058c7306b..299dc0bb9 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -109,11 +109,10 @@ bool OgreMeshFactory::IsLoaded(const MeshDescriptor &_desc) ////////////////////////////////////////////////// void OgreMeshFactory::ClearMaterialsCache() { - for (auto mat : this->materialCache) + for (auto &mat : this->materialCache) { std::string matName = mat->Name(); - mat->Destroy(); - this->scene->UnregisterMaterial(matName); + this->scene->DestroyMaterial(mat); } this->materialCache.clear(); } @@ -408,6 +407,7 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc) if (material) { mat->CopyFrom(*material); + materialCache.push_back(mat); } else { @@ -417,8 +417,6 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc) } ogreSubMesh->setMaterialName(mat->Name()); - materialCache.push_back(mat); - // Unlock vBuf->unlock(); iBuf->unlock(); From 41c0dae51a5abb46b828b7259b5387d8d53611cd Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 19 May 2021 22:50:17 +0200 Subject: [PATCH 03/14] make linters happy Signed-off-by: ahcorde --- ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh | 2 +- ogre/src/OgreMaterial.cc | 3 ++- ogre/src/OgreMesh.cc | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh index f27db716b..f0e4c7b0d 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh @@ -59,7 +59,7 @@ namespace ignition public: void ClearMaterialsCache(); protected: OgreScenePtr scene; - + protected: std::vector materialCache; }; diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index 1fffd3dab..2d6e47daf 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -51,7 +51,8 @@ void OgreMaterial::Destroy() { Ogre::TextureManager &texManager = Ogre::TextureManager::getSingleton(); - auto indexUnitStateToRemove = this->ogrePass->getTextureUnitStateIndex(this->ogreTexState); + auto indexUnitStateToRemove = + this->ogrePass->getTextureUnitStateIndex(this->ogreTexState); this->ogrePass->removeTextureUnitState(indexUnitStateToRemove); texManager.remove(this->textureName); diff --git a/ogre/src/OgreMesh.cc b/ogre/src/OgreMesh.cc index 0a431f0b8..d28af4c9b 100644 --- a/ogre/src/OgreMesh.cc +++ b/ogre/src/OgreMesh.cc @@ -58,7 +58,8 @@ void OgreMesh::Destroy() auto ogreScene = std::dynamic_pointer_cast(this->Scene()); - Ogre::MeshManager::getSingleton().remove(this->ogreEntity->getMesh()->getHandle()); + Ogre::MeshManager::getSingleton().remove( + this->ogreEntity->getMesh()->getHandle()); ogreScene->OgreSceneManager()->destroyEntity(this->ogreEntity); this->ogreEntity = nullptr; } From aee6715a5227bd1ad0212952937bc8438c43edf8 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 20 May 2021 22:16:19 +0200 Subject: [PATCH 04/14] Improved implementation Signed-off-by: ahcorde --- include/ignition/rendering/Scene.hh | 2 +- include/ignition/rendering/base/BaseScene.hh | 2 +- .../rendering/ogre/OgreMeshFactory.hh | 2 +- .../ignition/rendering/ogre/OgreScene.hh | 2 +- ogre/src/OgreMaterial.cc | 32 ++++++++++++++++--- ogre/src/OgreMeshFactory.cc | 17 ++++++++-- ogre/src/OgreScene.cc | 4 +-- .../rendering/ogre2/Ogre2MeshFactory.hh | 2 +- .../ignition/rendering/ogre2/Ogre2Scene.hh | 2 +- ogre2/src/Ogre2MeshFactory.cc | 2 +- ogre2/src/Ogre2Scene.cc | 4 +-- src/base/BaseScene.cc | 1 - 12 files changed, 53 insertions(+), 19 deletions(-) diff --git a/include/ignition/rendering/Scene.hh b/include/ignition/rendering/Scene.hh index bfbfc9fd8..f74be82b7 100644 --- a/include/ignition/rendering/Scene.hh +++ b/include/ignition/rendering/Scene.hh @@ -1032,7 +1032,7 @@ namespace ignition /// \brief When a mesh is loaded some material are cached in memory, then /// these materials are copied to the meshes. The method allows to remove /// this cache. - public: virtual void ClearMaterialsCache() = 0; + public: virtual void ClearMaterialsCache(const std::string &_name) = 0; }; } } diff --git a/include/ignition/rendering/base/BaseScene.hh b/include/ignition/rendering/base/BaseScene.hh index b2ada1333..350bdc3e1 100644 --- a/include/ignition/rendering/base/BaseScene.hh +++ b/include/ignition/rendering/base/BaseScene.hh @@ -665,7 +665,7 @@ namespace ignition private: virtual void CreateMaterials(); // Documentation inherited. - public: virtual void ClearMaterialsCache() = 0; + public: virtual void ClearMaterialsCache(const std::string &_name) = 0; /// \brief Helper function to recursively destory nodes while checking /// for loops. diff --git a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh index f0e4c7b0d..fd432cb1b 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh @@ -56,7 +56,7 @@ namespace ignition protected: virtual bool Validate(const MeshDescriptor &_desc); - public: void ClearMaterialsCache(); + public: void ClearMaterialsCache(const std::string &_name); protected: OgreScenePtr scene; diff --git a/ogre/include/ignition/rendering/ogre/OgreScene.hh b/ogre/include/ignition/rendering/ogre/OgreScene.hh index 1f57d20c5..0746ba56e 100644 --- a/ogre/include/ignition/rendering/ogre/OgreScene.hh +++ b/ogre/include/ignition/rendering/ogre/OgreScene.hh @@ -200,7 +200,7 @@ namespace ignition protected: virtual MaterialMapPtr Materials() const override; - public: virtual void ClearMaterialsCache() override; + public: virtual void ClearMaterialsCache(const std::string &_name) override; private: void CreateContext(); diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index 2d6e47daf..17cd642f4 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -44,21 +44,20 @@ void OgreMaterial::Destroy() { if (!this->Scene()->IsInitialized()) return; - + std::string materialName; Ogre::MaterialManager &matManager = Ogre::MaterialManager::getSingleton(); #if OGRE_VERSION_LT_1_10_1 if (!this->ogreMaterial.isNull()) { - Ogre::TextureManager &texManager = Ogre::TextureManager::getSingleton(); + materialName = this->ogreMaterial->getName(); + this->ogreTexState->setBlank(); auto indexUnitStateToRemove = this->ogrePass->getTextureUnitStateIndex(this->ogreTexState); this->ogrePass->removeTextureUnitState(indexUnitStateToRemove); - texManager.remove(this->textureName); matManager.remove(this->ogreMaterial->getName()); this->ogreMaterial.setNull(); - } #else if (this->ogreMaterial) { @@ -66,6 +65,30 @@ void OgreMaterial::Destroy() this->ogreMaterial.reset(); } #endif + auto iend = Ogre::TextureManager::getSingleton().getResourceIterator().end(); + for (auto i = Ogre::TextureManager::getSingleton().getResourceIterator().begin(); i != iend;) + { + // A use count of 4 means that only RGM, RM and MeshManager have references + // RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + if (i->second.useCount() == 4) + { + if (this->textureName == res->getName() && + res->getName().find("scene::RenderTexture") == std::string::npos) + { + this->Scene()->ClearMaterialsCache(this->textureName); + this->Scene()->UnregisterMaterial(materialName); + if (i->second.useCount() == 3) + { + Ogre::TextureManager::getSingleton().remove(res->getHandle()); + } + break; + } + } + ++i; + } + } } ////////////////////////////////////////////////// @@ -273,6 +296,7 @@ void OgreMaterial::SetTexture(const std::string &_name) } this->textureName = _name; + std::cerr << "OgreMaterial::SetTexture " << name << '\n'; this->SetTextureImpl(this->textureName); } diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index 299dc0bb9..636ff8926 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -107,14 +107,25 @@ bool OgreMeshFactory::IsLoaded(const MeshDescriptor &_desc) } ////////////////////////////////////////////////// -void OgreMeshFactory::ClearMaterialsCache() +void OgreMeshFactory::ClearMaterialsCache(const std::string &_name) { + std::cerr << "Unregisting material " << _name << '\n'; + auto it = this->materialCache.begin(); for (auto &mat : this->materialCache) { std::string matName = mat->Name(); - this->scene->DestroyMaterial(mat); + std::string textureName = mat->Texture(); + std::cerr << "Unregisting material " << matName << " " << textureName << '\n'; + + if (textureName == _name) + { + std::cerr << "Unregisting ok " << _name << '\n'; + this->scene->UnregisterMaterial(matName); + break; + } + ++it; } - this->materialCache.clear(); + this->materialCache.erase(it); } ////////////////////////////////////////////////// diff --git a/ogre/src/OgreScene.cc b/ogre/src/OgreScene.cc index f449ac1d5..ea13d4ae8 100644 --- a/ogre/src/OgreScene.cc +++ b/ogre/src/OgreScene.cc @@ -346,9 +346,9 @@ VisualStorePtr OgreScene::Visuals() const } ////////////////////////////////////////////////// -void OgreScene::ClearMaterialsCache() +void OgreScene::ClearMaterialsCache(const std::string &_name) { - this->meshFactory->ClearMaterialsCache(); + this->meshFactory->ClearMaterialsCache(_name); } ////////////////////////////////////////////////// diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh index e2b656d2a..2ad13cc87 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh @@ -95,7 +95,7 @@ namespace ignition protected: Ogre2ScenePtr scene; /// \brief Remove internal material cache - public: void ClearMaterialsCache(); + public: void ClearMaterialsCache(const std::string &_name); /// \brief Pointer to private data class private: std::unique_ptr dataPtr; diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh index ab4f1d16d..2de3c2f81 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh @@ -299,7 +299,7 @@ namespace ignition private: void CreateStores(); // Documentation inherited - public: virtual void ClearMaterialsCache() override; + public: virtual void ClearMaterialsCache(const std::string &_name) override; /// \brief Create a shared pointer to self private: Ogre2ScenePtr SharedThis(); diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index 826d560a8..16851b240 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -89,7 +89,7 @@ void Ogre2MeshFactory::Clear() this->ogreMeshes.clear(); } -void Ogre2MeshFactory::ClearMaterialsCache() +void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name) { for (auto mat : this->dataPtr->materialCache) { diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index 08151e3fa..59f53be0e 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -117,9 +117,9 @@ math::Color Ogre2Scene::AmbientLight() const } ////////////////////////////////////////////////// -void Ogre2Scene::ClearMaterialsCache() +void Ogre2Scene::ClearMaterialsCache(const std::string &_name) { - this->meshFactory->ClearMaterialsCache(); + this->meshFactory->ClearMaterialsCache(_name); } ////////////////////////////////////////////////// diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index f41422111..7a6315774 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -1049,7 +1049,6 @@ MeshPtr BaseScene::CreateMesh(const MeshDescriptor &_desc) unsigned int objId = this->CreateObjectId(); std::string objName = this->CreateObjectName(objId, "Mesh-" + meshName); MeshPtr mesh = this->CreateMeshImpl(objId, objName, _desc); - this->ClearMaterialsCache(); return mesh; } From 901c05907798c8c7313bb8bad71172c44a210c64 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 20 May 2021 22:32:28 +0200 Subject: [PATCH 05/14] make linters happy Signed-off-by: ahcorde --- ogre/include/ignition/rendering/ogre/OgreScene.hh | 3 ++- ogre/src/OgreMaterial.cc | 8 ++++---- ogre/src/OgreMeshFactory.cc | 4 ---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ogre/include/ignition/rendering/ogre/OgreScene.hh b/ogre/include/ignition/rendering/ogre/OgreScene.hh index 0746ba56e..93c0aae2a 100644 --- a/ogre/include/ignition/rendering/ogre/OgreScene.hh +++ b/ogre/include/ignition/rendering/ogre/OgreScene.hh @@ -200,7 +200,8 @@ namespace ignition protected: virtual MaterialMapPtr Materials() const override; - public: virtual void ClearMaterialsCache(const std::string &_name) override; + public: virtual void + ClearMaterialsCache(const std::string &_name) override; private: void CreateContext(); diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index 17cd642f4..c5ef99603 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -65,8 +65,9 @@ void OgreMaterial::Destroy() this->ogreMaterial.reset(); } #endif - auto iend = Ogre::TextureManager::getSingleton().getResourceIterator().end(); - for (auto i = Ogre::TextureManager::getSingleton().getResourceIterator().begin(); i != iend;) + auto &textureManager = Ogre::TextureManager::getSingleton(); + auto iend = textureManager.getResourceIterator().end(); + for (auto i = textureManager.getResourceIterator().begin(); i != iend;) { // A use count of 4 means that only RGM, RM and MeshManager have references // RGM has one (this one) and RM has 2 (by name and by handle) @@ -81,7 +82,7 @@ void OgreMaterial::Destroy() this->Scene()->UnregisterMaterial(materialName); if (i->second.useCount() == 3) { - Ogre::TextureManager::getSingleton().remove(res->getHandle()); + textureManager.remove(res->getHandle()); } break; } @@ -296,7 +297,6 @@ void OgreMaterial::SetTexture(const std::string &_name) } this->textureName = _name; - std::cerr << "OgreMaterial::SetTexture " << name << '\n'; this->SetTextureImpl(this->textureName); } diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index 636ff8926..517040826 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -109,17 +109,13 @@ bool OgreMeshFactory::IsLoaded(const MeshDescriptor &_desc) ////////////////////////////////////////////////// void OgreMeshFactory::ClearMaterialsCache(const std::string &_name) { - std::cerr << "Unregisting material " << _name << '\n'; auto it = this->materialCache.begin(); for (auto &mat : this->materialCache) { std::string matName = mat->Name(); std::string textureName = mat->Texture(); - std::cerr << "Unregisting material " << matName << " " << textureName << '\n'; - if (textureName == _name) { - std::cerr << "Unregisting ok " << _name << '\n'; this->scene->UnregisterMaterial(matName); break; } From e5b338755b0894a2947854997986f68edf627a0d Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 21 May 2021 22:27:45 +0200 Subject: [PATCH 06/14] Ogre2 texture destruction some progress Signed-off-by: ahcorde --- .../ignition/rendering/ogre2/Ogre2Mesh.hh | 6 ++ ogre2/src/Ogre2Material.cc | 58 ++++++++++++++++--- ogre2/src/Ogre2Mesh.cc | 16 +++++ ogre2/src/Ogre2MeshFactory.cc | 23 ++++++-- src/base/BaseScene.cc | 3 +- 5 files changed, 92 insertions(+), 14 deletions(-) diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh index a6ae4c070..ad98603e1 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh @@ -118,6 +118,12 @@ namespace ignition /// \brief Destructor public: virtual ~Ogre2SubMesh(); + // Documentation inherited + public: virtual void Destroy() override; + + // Documentation inherited + public: void SetMeshName(const std::string &_name); + /// \brief Get internal ogre subitem created from this submesh public: virtual Ogre::SubItem *Ogre2SubItem() const; diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index a721e6b11..b71370dbe 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef _MSC_VER #pragma warning(pop) #endif @@ -44,6 +45,7 @@ /// \brief Private data for the Ogre2Material class class ignition::rendering::Ogre2MaterialPrivate { + public: std::string hashName; }; using namespace ignition; @@ -70,13 +72,6 @@ void Ogre2Material::Destroy() if (!this->ogreDatablock) return; - if (!this->textureName.empty()) - { - Ogre::HlmsTextureManager *hlmsTextureManager = - this->ogreHlmsPbs->getHlmsManager()->getTextureManager(); - hlmsTextureManager->destroyTexture(this->textureName); - } - this->ogreHlmsPbs->destroyDatablock(this->ogreDatablockId); this->ogreDatablock = nullptr; @@ -94,6 +89,40 @@ void Ogre2Material::Destroy() matManager.remove(this->ogreMaterial); this->ogreMaterial.reset(); } + + auto &textureManager = Ogre::TextureManager::getSingleton(); + auto iend = textureManager.getResourceIterator().end(); + for (auto i = textureManager.getResourceIterator().begin(); i != iend;) + { + // A use count of 4 means that only RGM, RM and MeshManager have references + // RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + std::cerr << "res " << res->getName() << " " << i->second.useCount() << '\n'; + if (i->second.useCount() == 5) + { + if (this->dataPtr->hashName == res->getName() && + res->getName().find("scene::RenderTexture") == std::string::npos) + { + std::cerr << "Ogre2Material::Destroy materialName " << Name() << this->textureName << '\n'; + + this->Scene()->ClearMaterialsCache(this->textureName); + this->Scene()->UnregisterMaterial(this->name); + if (i->second.useCount() == 4) + { + textureManager.remove(res->getHandle()); + if (!this->textureName.empty()) + { + Ogre::HlmsTextureManager *hlmsTextureManager = + this->ogreHlmsPbs->getHlmsManager()->getTextureManager(); + hlmsTextureManager->destroyTexture(this->textureName); + } + } + break; + } + } + ++i; + } } ////////////////////////////////////////////////// @@ -235,6 +264,19 @@ void Ogre2Material::SetTexture(const std::string &_name) this->textureName = _name; this->SetTextureMapImpl(this->textureName, Ogre::PBSM_DIFFUSE); + + auto &textureManager = Ogre::TextureManager::getSingleton(); + auto iend = textureManager.getResourceIterator().end(); + for (auto i = textureManager.getResourceIterator().begin(); i != iend;) + { + // A use count of 4 means that only RGM, RM and MeshManager have references + // RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + std::cerr << "res 4 " << res->getName() << " " << i->second.useCount() << '\n'; + i++; + } + } ////////////////////////////////////////////////// @@ -545,6 +587,7 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture, Ogre::HlmsTextureManager::TextureLocation texLocation = hlmsTextureManager->createOrRetrieveTexture(baseName, this->ogreDatablock->suggestMapTypeBasedOnTextureType(_type)); + this->dataPtr->hashName = texLocation.texture->getName(); Ogre::HlmsSamplerblock samplerBlockRef; samplerBlockRef.mU = Ogre::TAM_WRAP; @@ -687,6 +730,7 @@ void Ogre2Material::FillUnlitDatablock(Ogre::HlmsUnlitDatablock *_datablock) this->ogreDatablock->suggestMapTypeBasedOnTextureType( Ogre::PBSM_DIFFUSE)); _datablock->setTexture(0, texLocation.xIdx, texLocation.texture); + std::cerr << "NAME LAEX " << texLocation.texture->getName() << '\n'; } auto samplerblock = this->ogreDatablock->getSamplerblock(Ogre::PBSM_DIFFUSE); diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index f47ee04cb..2c9b5e402 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #ifdef _MSC_VER #pragma warning(pop) #endif @@ -280,6 +283,19 @@ Ogre2SubMesh::~Ogre2SubMesh() this->Destroy(); } +std::string subMeshName; +void Ogre2SubMesh::SetMeshName(const std::string &_name) +{ + subMeshName = _name; +} + +void Ogre2SubMesh::Destroy() +{ + Ogre::v1::MeshManager::getSingleton().remove(subMeshName); + Ogre::MeshManager::getSingleton().remove(subMeshName); + BaseSubMesh::Destroy(); +} + ////////////////////////////////////////////////// Ogre::SubItem *Ogre2SubMesh::Ogre2SubItem() const { diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index 16851b240..be8e2bf07 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -91,13 +91,20 @@ void Ogre2MeshFactory::Clear() void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name) { - for (auto mat : this->dataPtr->materialCache) + auto it = this->dataPtr->materialCache.begin(); + for (auto &mat : this->dataPtr->materialCache) { std::string matName = mat->Name(); - mat->Destroy(); - this->scene->UnregisterMaterial(matName); + std::string textureName = mat->Texture(); + if (textureName == _name) + { + std::cerr << "UnregisterMaterial " << _name << '\n'; + this->scene->UnregisterMaterial(matName); + break; + } + ++it; } - this->dataPtr->materialCache.clear(); + this->dataPtr->materialCache.erase(it); } ////////////////////////////////////////////////// @@ -120,6 +127,12 @@ Ogre2MeshPtr Ogre2MeshFactory::Create(const MeshDescriptor &_desc) // create sub-mesh store Ogre2SubMeshStoreFactory subMeshFactory(this->scene, mesh->ogreItem); mesh->subMeshes = subMeshFactory.Create(); + for (unsigned int i = 0; i < mesh->subMeshes->Size(); i++) + { + Ogre2SubMeshPtr submesh = + std::dynamic_pointer_cast(mesh->subMeshes->GetById(i)); + submesh->SetMeshName(this->MeshName(_desc)); + } return mesh; } @@ -459,6 +472,7 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc) if (material) { mat->CopyFrom(*material); + this->dataPtr->materialCache.push_back(mat); } else { @@ -467,7 +481,6 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc) mat->CopyFrom(defaultMat); } ogreSubMesh->setMaterialName(mat->Name()); - this->dataPtr->materialCache.push_back(mat); } math::Vector3d max = _desc.mesh->Max(); diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index 7a6315774..76094afb8 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -1048,8 +1048,7 @@ MeshPtr BaseScene::CreateMesh(const MeshDescriptor &_desc) unsigned int objId = this->CreateObjectId(); std::string objName = this->CreateObjectName(objId, "Mesh-" + meshName); - MeshPtr mesh = this->CreateMeshImpl(objId, objName, _desc); - return mesh; + return this->CreateMeshImpl(objId, objName, _desc); } ////////////////////////////////////////////////// From eb968a99467552df5391a7b728aeea0beb04bd92 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 12:18:38 +0200 Subject: [PATCH 07/14] Remove meshes when there is no reference Signed-off-by: ahcorde --- ogre/src/OgreMesh.cc | 24 +++++++++++++++++++++--- ogre2/src/Ogre2Mesh.cc | 21 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/ogre/src/OgreMesh.cc b/ogre/src/OgreMesh.cc index d28af4c9b..1b015f491 100644 --- a/ogre/src/OgreMesh.cc +++ b/ogre/src/OgreMesh.cc @@ -58,10 +58,29 @@ void OgreMesh::Destroy() auto ogreScene = std::dynamic_pointer_cast(this->Scene()); - Ogre::MeshManager::getSingleton().remove( - this->ogreEntity->getMesh()->getHandle()); + std::string ogreMeshName = this->ogreEntity->getMesh()->getName(); + ogreScene->OgreSceneManager()->destroyEntity(this->ogreEntity); this->ogreEntity = nullptr; + + auto &meshManager = Ogre::MeshManager::getSingleton(); + auto iend = meshManager.getResourceIterator().end(); + for (auto i = meshManager.getResourceIterator().begin(); i != iend;) + { + // A use count of 4 means that only RGM, RM and MeshManager have references + // RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + if (i->second.useCount() == 3) + { + if (res->getName() == ogreMeshName) + { + Ogre::MeshManager::getSingleton().remove(ogreMeshName); + break; + } + } + i++; + } } ////////////////////////////////////////////////// @@ -286,7 +305,6 @@ Ogre::SubEntity *OgreSubMesh::OgreSubEntity() const ////////////////////////////////////////////////// void OgreSubMesh::Destroy() { - Ogre::MeshManager::getSingleton().remove(this->Name()); Ogre::MaterialManager::getSingleton().remove( this->ogreSubEntity->getMaterialName()); OgreRTShaderSystem::Instance()->DetachEntity(this); diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index 2c9b5e402..01e4387f6 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -291,8 +291,25 @@ void Ogre2SubMesh::SetMeshName(const std::string &_name) void Ogre2SubMesh::Destroy() { - Ogre::v1::MeshManager::getSingleton().remove(subMeshName); - Ogre::MeshManager::getSingleton().remove(subMeshName); + auto &meshManager = Ogre::MeshManager::getSingleton(); + auto iend = meshManager.getResourceIterator().end(); + for (auto i = meshManager.getResourceIterator().begin(); i != iend;) + { + // A use count of 4 means that only RGM, RM and MeshManager have references + // RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + if (i->second.useCount() == 3) + { + if (res->getName() == subMeshName) + { + Ogre::v1::MeshManager::getSingleton().remove(subMeshName); + Ogre::MeshManager::getSingleton().remove(subMeshName); + break; + } + } + ++i; + } BaseSubMesh::Destroy(); } From 95db6a6073858c4ac36af20b69482ba64bf7d271 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 12:50:14 +0200 Subject: [PATCH 08/14] cleanup code Signed-off-by: ahcorde --- ogre/src/OgreMaterial.cc | 4 ++-- .../ignition/rendering/ogre2/Ogre2Mesh.hh | 4 ++++ .../ignition/rendering/ogre2/Ogre2Scene.hh | 3 ++- ogre2/src/Ogre2Material.cc | 16 ---------------- ogre2/src/Ogre2Mesh.cc | 18 +++++++++++++----- ogre2/src/Ogre2MeshFactory.cc | 1 - 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index c5ef99603..d93fcdb89 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -69,8 +69,8 @@ void OgreMaterial::Destroy() auto iend = textureManager.getResourceIterator().end(); for (auto i = textureManager.getResourceIterator().begin(); i != iend;) { - // A use count of 4 means that only RGM, RM and MeshManager have references - // RGM has one (this one) and RM has 2 (by name and by handle) + // A use count of 4 means that only RGM, RM and MeshManager have + // references RGM has one (this one) and RM has 2 (by name and by handle) // and MeshManager keep another one int the template Ogre::Resource* res = i->second.get(); if (i->second.useCount() == 4) diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh index ad98603e1..e002ce78a 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh @@ -41,6 +41,7 @@ namespace ignition // // forward declaration class Ogre2MeshPrivate; + class Ogre2SubMeshPrivate; /// \brief Ogre2.x implementation of the mesh class class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2Mesh : @@ -143,6 +144,9 @@ namespace ignition /// \brief Make submesh factory our friend so it can create an /// ogre2 submesh private: friend class Ogre2SubMeshStoreFactory; + + /// \brief Pointer to private data + private: std::unique_ptr dataPtr; }; } } diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh index 2de3c2f81..98eefd728 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh @@ -299,7 +299,8 @@ namespace ignition private: void CreateStores(); // Documentation inherited - public: virtual void ClearMaterialsCache(const std::string &_name) override; + public: virtual void ClearMaterialsCache(const std::string &_name) + override; /// \brief Create a shared pointer to self private: Ogre2ScenePtr SharedThis(); diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index b71370dbe..89d3b0255 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -98,14 +98,11 @@ void Ogre2Material::Destroy() // RGM has one (this one) and RM has 2 (by name and by handle) // and MeshManager keep another one int the template Ogre::Resource* res = i->second.get(); - std::cerr << "res " << res->getName() << " " << i->second.useCount() << '\n'; if (i->second.useCount() == 5) { if (this->dataPtr->hashName == res->getName() && res->getName().find("scene::RenderTexture") == std::string::npos) { - std::cerr << "Ogre2Material::Destroy materialName " << Name() << this->textureName << '\n'; - this->Scene()->ClearMaterialsCache(this->textureName); this->Scene()->UnregisterMaterial(this->name); if (i->second.useCount() == 4) @@ -264,19 +261,6 @@ void Ogre2Material::SetTexture(const std::string &_name) this->textureName = _name; this->SetTextureMapImpl(this->textureName, Ogre::PBSM_DIFFUSE); - - auto &textureManager = Ogre::TextureManager::getSingleton(); - auto iend = textureManager.getResourceIterator().end(); - for (auto i = textureManager.getResourceIterator().begin(); i != iend;) - { - // A use count of 4 means that only RGM, RM and MeshManager have references - // RGM has one (this one) and RM has 2 (by name and by handle) - // and MeshManager keep another one int the template - Ogre::Resource* res = i->second.get(); - std::cerr << "res 4 " << res->getName() << " " << i->second.useCount() << '\n'; - i++; - } - } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index 01e4387f6..18ba4d6f8 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -43,6 +43,14 @@ class ignition::rendering::Ogre2MeshPrivate { }; +/// brief Private implementation of the Ogre2SubMesh class +class ignition::rendering::Ogre2SubMeshPrivate +{ + /// \brief name of the mesh inside the mesh manager to be able to + /// remove it + public: std::string subMeshName; +}; + using namespace ignition; using namespace rendering; @@ -274,6 +282,7 @@ SubMeshStorePtr Ogre2Mesh::SubMeshes() const ////////////////////////////////////////////////// Ogre2SubMesh::Ogre2SubMesh() + : dataPtr(new Ogre2SubMeshPrivate) { } @@ -283,10 +292,9 @@ Ogre2SubMesh::~Ogre2SubMesh() this->Destroy(); } -std::string subMeshName; void Ogre2SubMesh::SetMeshName(const std::string &_name) { - subMeshName = _name; + this->dataPtr->subMeshName = _name; } void Ogre2SubMesh::Destroy() @@ -301,10 +309,10 @@ void Ogre2SubMesh::Destroy() Ogre::Resource* res = i->second.get(); if (i->second.useCount() == 3) { - if (res->getName() == subMeshName) + if (res->getName() == this->dataPtr->subMeshName) { - Ogre::v1::MeshManager::getSingleton().remove(subMeshName); - Ogre::MeshManager::getSingleton().remove(subMeshName); + Ogre::v1::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); + Ogre::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); break; } } diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index be8e2bf07..d626a651a 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -98,7 +98,6 @@ void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name) std::string textureName = mat->Texture(); if (textureName == _name) { - std::cerr << "UnregisterMaterial " << _name << '\n'; this->scene->UnregisterMaterial(matName); break; } From 8e3d392bfffaa38693c8c062fe0b92d8512da79c Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 13:04:10 +0200 Subject: [PATCH 09/14] Avoid breaking ABI Signed-off-by: ahcorde --- include/ignition/rendering/Scene.hh | 5 ----- include/ignition/rendering/base/BaseScene.hh | 3 --- ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh | 1 + ogre/include/ignition/rendering/ogre/OgreScene.hh | 3 +-- ogre/src/OgreMaterial.cc | 3 ++- ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh | 2 +- ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh | 3 +-- ogre2/src/Ogre2Material.cc | 3 ++- 8 files changed, 8 insertions(+), 15 deletions(-) diff --git a/include/ignition/rendering/Scene.hh b/include/ignition/rendering/Scene.hh index f74be82b7..b61404580 100644 --- a/include/ignition/rendering/Scene.hh +++ b/include/ignition/rendering/Scene.hh @@ -1028,11 +1028,6 @@ namespace ignition /// use of this scene after its destruction will result in undefined /// behavior. public: virtual void Destroy() = 0; - - /// \brief When a mesh is loaded some material are cached in memory, then - /// these materials are copied to the meshes. The method allows to remove - /// this cache. - public: virtual void ClearMaterialsCache(const std::string &_name) = 0; }; } } diff --git a/include/ignition/rendering/base/BaseScene.hh b/include/ignition/rendering/base/BaseScene.hh index 350bdc3e1..31670265b 100644 --- a/include/ignition/rendering/base/BaseScene.hh +++ b/include/ignition/rendering/base/BaseScene.hh @@ -664,9 +664,6 @@ namespace ignition private: virtual void CreateMaterials(); - // Documentation inherited. - public: virtual void ClearMaterialsCache(const std::string &_name) = 0; - /// \brief Helper function to recursively destory nodes while checking /// for loops. /// \param[in] _node Node to be destroyed diff --git a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh index fd432cb1b..259b56806 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh @@ -56,6 +56,7 @@ namespace ignition protected: virtual bool Validate(const MeshDescriptor &_desc); + /// \brief Remove internal material cache fot a specific material public: void ClearMaterialsCache(const std::string &_name); protected: OgreScenePtr scene; diff --git a/ogre/include/ignition/rendering/ogre/OgreScene.hh b/ogre/include/ignition/rendering/ogre/OgreScene.hh index 93c0aae2a..0a1fd6ba1 100644 --- a/ogre/include/ignition/rendering/ogre/OgreScene.hh +++ b/ogre/include/ignition/rendering/ogre/OgreScene.hh @@ -200,8 +200,7 @@ namespace ignition protected: virtual MaterialMapPtr Materials() const override; - public: virtual void - ClearMaterialsCache(const std::string &_name) override; + public: void ClearMaterialsCache(const std::string &_name); private: void CreateContext(); diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index d93fcdb89..bbe83e883 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -78,7 +78,8 @@ void OgreMaterial::Destroy() if (this->textureName == res->getName() && res->getName().find("scene::RenderTexture") == std::string::npos) { - this->Scene()->ClearMaterialsCache(this->textureName); + OgreScenePtr s = std::dynamic_pointer_cast(this->Scene()); + s->ClearMaterialsCache(this->textureName); this->Scene()->UnregisterMaterial(materialName); if (i->second.useCount() == 3) { diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh index 2ad13cc87..b706a3aeb 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh @@ -94,7 +94,7 @@ namespace ignition /// \brief Pointer to the scene object protected: Ogre2ScenePtr scene; - /// \brief Remove internal material cache + /// \brief Remove internal material cache fot a specific material public: void ClearMaterialsCache(const std::string &_name); /// \brief Pointer to private data class diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh index 98eefd728..ead1319bf 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh @@ -299,8 +299,7 @@ namespace ignition private: void CreateStores(); // Documentation inherited - public: virtual void ClearMaterialsCache(const std::string &_name) - override; + public: void ClearMaterialsCache(const std::string &_name); /// \brief Create a shared pointer to self private: Ogre2ScenePtr SharedThis(); diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index 89d3b0255..fcf09719d 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -103,7 +103,8 @@ void Ogre2Material::Destroy() if (this->dataPtr->hashName == res->getName() && res->getName().find("scene::RenderTexture") == std::string::npos) { - this->Scene()->ClearMaterialsCache(this->textureName); + Ogre2ScenePtr s = std::dynamic_pointer_cast(this->Scene()); + s->ClearMaterialsCache(this->textureName); this->Scene()->UnregisterMaterial(this->name); if (i->second.useCount() == 4) { From 27e51f00ad1faffdcabe22614285975ce03657d1 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 13:08:42 +0200 Subject: [PATCH 10/14] make linters happy Signed-off-by: ahcorde --- ogre2/src/Ogre2Mesh.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index 18ba4d6f8..89a16e3d7 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -311,7 +311,8 @@ void Ogre2SubMesh::Destroy() { if (res->getName() == this->dataPtr->subMeshName) { - Ogre::v1::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); + Ogre::v1::MeshManager::getSingleton().remove( + this->dataPtr->subMeshName); Ogre::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); break; } From 5ab7dcc863c0789c25b6e6ce8481d3f5b73e3d18 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 16:38:17 +0200 Subject: [PATCH 11/14] Fixed tests Signed-off-by: ahcorde --- ogre2/src/Ogre2Mesh.cc | 31 +++++++++++++++++-------------- ogre2/src/Ogre2MeshFactory.cc | 3 ++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index 89a16e3d7..f03b20db7 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -299,25 +299,28 @@ void Ogre2SubMesh::SetMeshName(const std::string &_name) void Ogre2SubMesh::Destroy() { - auto &meshManager = Ogre::MeshManager::getSingleton(); - auto iend = meshManager.getResourceIterator().end(); - for (auto i = meshManager.getResourceIterator().begin(); i != iend;) + auto meshManager = Ogre::MeshManager::getSingletonPtr(); + if (meshManager) { - // A use count of 4 means that only RGM, RM and MeshManager have references - // RGM has one (this one) and RM has 2 (by name and by handle) - // and MeshManager keep another one int the template - Ogre::Resource* res = i->second.get(); - if (i->second.useCount() == 3) + auto iend = meshManager->getResourceIterator().end(); + for (auto i = meshManager->getResourceIterator().begin(); i != iend;) { - if (res->getName() == this->dataPtr->subMeshName) + // A use count of 4 means that only RGM, RM and MeshManager have + // references RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + if (i->second.useCount() == 3) { - Ogre::v1::MeshManager::getSingleton().remove( - this->dataPtr->subMeshName); - Ogre::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); - break; + if (res->getName() == this->dataPtr->subMeshName) + { + Ogre::v1::MeshManager::getSingleton().remove( + this->dataPtr->subMeshName); + Ogre::MeshManager::getSingleton().remove(this->dataPtr->subMeshName); + break; + } } + ++i; } - ++i; } BaseSubMesh::Destroy(); } diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index d626a651a..f0d7b2f20 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -103,7 +103,8 @@ void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name) } ++it; } - this->dataPtr->materialCache.erase(it); + if (it != this->dataPtr->materialCache.end()) + this->dataPtr->materialCache.erase(it); } ////////////////////////////////////////////////// From 0b4e4019faa4c211787136852298ad50a8386620 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 24 May 2021 18:47:16 +0200 Subject: [PATCH 12/14] Fix macos warnings Signed-off-by: ahcorde --- ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh index e002ce78a..7ed220365 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh @@ -130,10 +130,10 @@ namespace ignition /// \brief Helper function for setting the material to use /// \param[in] _material Material to be assigned to the submesh - protected: virtual void SetMaterialImpl(MaterialPtr _material); + protected: virtual void SetMaterialImpl(MaterialPtr _material) override; /// \brief Initialize the submesh - protected: virtual void Init(); + protected: virtual void Init() override; /// \brief Ogre subitem representing the submesh protected: Ogre::SubItem *ogreSubItem = nullptr; From 535731a16e9e68adf5f78ea5a124b88595cac5a4 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 25 May 2021 10:43:44 +0200 Subject: [PATCH 13/14] Added feedback Signed-off-by: ahcorde --- .../rendering/ogre/OgreMeshFactory.hh | 5 ++- .../ignition/rendering/ogre/OgreScene.hh | 2 ++ ogre/src/OgreMaterial.cc | 33 ++++++++++--------- ogre/src/OgreMesh.cc | 3 +- ogre/src/OgreMeshFactory.cc | 3 +- .../ignition/rendering/ogre2/Ogre2Mesh.hh | 3 +- .../rendering/ogre2/Ogre2MeshFactory.hh | 2 +- .../ignition/rendering/ogre2/Ogre2Scene.hh | 3 +- ogre2/src/Ogre2Material.cc | 6 ++-- ogre2/src/Ogre2Mesh.cc | 5 +-- ogre2/src/Ogre2MeshFactory.cc | 3 ++ 11 files changed, 41 insertions(+), 27 deletions(-) diff --git a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh index 259b56806..6c28369ab 100644 --- a/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh +++ b/ogre/include/ignition/rendering/ogre/OgreMeshFactory.hh @@ -56,11 +56,14 @@ namespace ignition protected: virtual bool Validate(const MeshDescriptor &_desc); - /// \brief Remove internal material cache fot a specific material + /// \brief Remove internal material cache for a specific material + /// \param[in] _name Name of the template material to remove. public: void ClearMaterialsCache(const std::string &_name); protected: OgreScenePtr scene; + /// \brief Vector with the template materials, we keep the pointer to be + /// able to remove it when nobody is using it. protected: std::vector materialCache; }; diff --git a/ogre/include/ignition/rendering/ogre/OgreScene.hh b/ogre/include/ignition/rendering/ogre/OgreScene.hh index 0a1fd6ba1..fca6a5c2d 100644 --- a/ogre/include/ignition/rendering/ogre/OgreScene.hh +++ b/ogre/include/ignition/rendering/ogre/OgreScene.hh @@ -200,6 +200,8 @@ namespace ignition protected: virtual MaterialMapPtr Materials() const override; + /// \brief Remove internal material cache for a specific material + /// \param[in] _name Name of the template material to remove. public: void ClearMaterialsCache(const std::string &_name); private: void CreateContext(); diff --git a/ogre/src/OgreMaterial.cc b/ogre/src/OgreMaterial.cc index bbe83e883..229164b75 100644 --- a/ogre/src/OgreMaterial.cc +++ b/ogre/src/OgreMaterial.cc @@ -58,6 +58,7 @@ void OgreMaterial::Destroy() matManager.remove(this->ogreMaterial->getName()); this->ogreMaterial.setNull(); + } #else if (this->ogreMaterial) { @@ -69,27 +70,27 @@ void OgreMaterial::Destroy() auto iend = textureManager.getResourceIterator().end(); for (auto i = textureManager.getResourceIterator().begin(); i != iend;) { - // A use count of 4 means that only RGM, RM and MeshManager have - // references RGM has one (this one) and RM has 2 (by name and by handle) - // and MeshManager keep another one int the template - Ogre::Resource* res = i->second.get(); - if (i->second.useCount() == 4) + // A use count of 4 means that only RGM, RM and MeshManager have + // references RGM has one (this one) and RM has 2 (by name and by handle) + // and MeshManager keep another one int the template + Ogre::Resource* res = i->second.get(); + if (i->second.useCount() == 4) + { + if (this->textureName == res->getName() && + res->getName().find( + scene->Name() + "::RenderTexture") == std::string::npos) { - if (this->textureName == res->getName() && - res->getName().find("scene::RenderTexture") == std::string::npos) + OgreScenePtr s = std::dynamic_pointer_cast(this->Scene()); + s->ClearMaterialsCache(this->textureName); + this->Scene()->UnregisterMaterial(materialName); + if (i->second.useCount() == 3) { - OgreScenePtr s = std::dynamic_pointer_cast(this->Scene()); - s->ClearMaterialsCache(this->textureName); - this->Scene()->UnregisterMaterial(materialName); - if (i->second.useCount() == 3) - { - textureManager.remove(res->getHandle()); - } - break; + textureManager.remove(res->getHandle()); } + break; } - ++i; } + ++i; } } diff --git a/ogre/src/OgreMesh.cc b/ogre/src/OgreMesh.cc index 1b015f491..bf77874a7 100644 --- a/ogre/src/OgreMesh.cc +++ b/ogre/src/OgreMesh.cc @@ -67,9 +67,8 @@ void OgreMesh::Destroy() auto iend = meshManager.getResourceIterator().end(); for (auto i = meshManager.getResourceIterator().begin(); i != iend;) { - // A use count of 4 means that only RGM, RM and MeshManager have references + // A use count of 3 means that only RGM and RM have references // RGM has one (this one) and RM has 2 (by name and by handle) - // and MeshManager keep another one int the template Ogre::Resource* res = i->second.get(); if (i->second.useCount() == 3) { diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index 517040826..5033c61eb 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -121,7 +121,8 @@ void OgreMeshFactory::ClearMaterialsCache(const std::string &_name) } ++it; } - this->materialCache.erase(it); + if (it != this->materialCache.end()) + this->materialCache.erase(it); } ////////////////////////////////////////////////// diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh index 7ed220365..9b5e0448c 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Mesh.hh @@ -122,7 +122,8 @@ namespace ignition // Documentation inherited public: virtual void Destroy() override; - // Documentation inherited + /// \brief Set the name of the mesh stored in Ogre2 + /// \param[in] _name Name of the mesh public: void SetMeshName(const std::string &_name); /// \brief Get internal ogre subitem created from this submesh diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh index b706a3aeb..202607cea 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2MeshFactory.hh @@ -94,7 +94,7 @@ namespace ignition /// \brief Pointer to the scene object protected: Ogre2ScenePtr scene; - /// \brief Remove internal material cache fot a specific material + /// \brief Remove internal material cache for a specific material public: void ClearMaterialsCache(const std::string &_name); /// \brief Pointer to private data class diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh index ead1319bf..e4d05a2f9 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2Scene.hh @@ -298,7 +298,8 @@ namespace ignition /// \brief Create the vaiours storage objects private: void CreateStores(); - // Documentation inherited + /// \brief Remove internal material cache for a specific material + /// \param[in] _name Name of the template material to remove. public: void ClearMaterialsCache(const std::string &_name); /// \brief Create a shared pointer to self diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index fcf09719d..024ac33ef 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -45,6 +45,8 @@ /// \brief Private data for the Ogre2Material class class ignition::rendering::Ogre2MaterialPrivate { + /// \brief Ogre stores the name using hashes. This variable will + /// store the material hash name public: std::string hashName; }; @@ -101,7 +103,8 @@ void Ogre2Material::Destroy() if (i->second.useCount() == 5) { if (this->dataPtr->hashName == res->getName() && - res->getName().find("scene::RenderTexture") == std::string::npos) + res->getName().find( + scene->Name() + "::RenderTexture") == std::string::npos) { Ogre2ScenePtr s = std::dynamic_pointer_cast(this->Scene()); s->ClearMaterialsCache(this->textureName); @@ -715,7 +718,6 @@ void Ogre2Material::FillUnlitDatablock(Ogre::HlmsUnlitDatablock *_datablock) this->ogreDatablock->suggestMapTypeBasedOnTextureType( Ogre::PBSM_DIFFUSE)); _datablock->setTexture(0, texLocation.xIdx, texLocation.texture); - std::cerr << "NAME LAEX " << texLocation.texture->getName() << '\n'; } auto samplerblock = this->ogreDatablock->getSamplerblock(Ogre::PBSM_DIFFUSE); diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index f03b20db7..3e46ee8ab 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -292,11 +292,13 @@ Ogre2SubMesh::~Ogre2SubMesh() this->Destroy(); } +////////////////////////////////////////////////// void Ogre2SubMesh::SetMeshName(const std::string &_name) { this->dataPtr->subMeshName = _name; } +////////////////////////////////////////////////// void Ogre2SubMesh::Destroy() { auto meshManager = Ogre::MeshManager::getSingletonPtr(); @@ -305,9 +307,8 @@ void Ogre2SubMesh::Destroy() auto iend = meshManager->getResourceIterator().end(); for (auto i = meshManager->getResourceIterator().begin(); i != iend;) { - // A use count of 4 means that only RGM, RM and MeshManager have + // A use count of 43 means that only RGM and RM have // references RGM has one (this one) and RM has 2 (by name and by handle) - // and MeshManager keep another one int the template Ogre::Resource* res = i->second.get(); if (i->second.useCount() == 3) { diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index f0d7b2f20..a896332b2 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -58,6 +58,8 @@ /// \brief Private data for the Ogre2MeshFactory class class ignition::rendering::Ogre2MeshFactoryPrivate { + /// \brief Vector with the template materials, we keep the pointer to be + /// able to remove it when nobody is using it. public: std::vector materialCache; }; @@ -89,6 +91,7 @@ void Ogre2MeshFactory::Clear() this->ogreMeshes.clear(); } +////////////////////////////////////////////////// void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name) { auto it = this->dataPtr->materialCache.begin(); From e3b10e83cd34217c25f8820a79561ac28d8319bb Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 27 May 2021 19:36:26 +0200 Subject: [PATCH 14/14] Doc fix Signed-off-by: ahcorde --- ogre2/src/Ogre2Mesh.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ogre2/src/Ogre2Mesh.cc b/ogre2/src/Ogre2Mesh.cc index 3e46ee8ab..cff027eb3 100644 --- a/ogre2/src/Ogre2Mesh.cc +++ b/ogre2/src/Ogre2Mesh.cc @@ -307,7 +307,7 @@ void Ogre2SubMesh::Destroy() auto iend = meshManager->getResourceIterator().end(); for (auto i = meshManager->getResourceIterator().begin(); i != iend;) { - // A use count of 43 means that only RGM and RM have + // A use count of 3 means that only RGM and RM have // references RGM has one (this one) and RM has 2 (by name and by handle) Ogre::Resource* res = i->second.get(); if (i->second.useCount() == 3)