Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ClearMaterialsCache call when a material is destroyed in ogre2 (backport #1110) #1111

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2MeshFactory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace gz
protected: Ogre2ScenePtr scene;

/// \brief Remove internal material cache for a specific material
/// \todo(iche033) Deprecate this function in gz-rendering10
public: void ClearMaterialsCache(const std::string &_name);

/// \brief Pointer to private data class
Expand Down
1 change: 1 addition & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ namespace gz

/// \brief Remove internal material cache for a specific material
/// \param[in] _name Name of the template material to remove.
/// \todo(iche033) Deprecate this function in gz-rendering10
public: void ClearMaterialsCache(const std::string &_name);

/// \brief Create a shared pointer to self
Expand Down
2 changes: 0 additions & 2 deletions ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ void Ogre2Material::Destroy()

if (textureToRemove && !textureIsUse)
{
Ogre2ScenePtr s = std::dynamic_pointer_cast<Ogre2Scene>(this->Scene());
s->ClearMaterialsCache(this->textureName);
this->Scene()->UnregisterMaterial(this->name);
textureManager->destroyTexture(textureToRemove);
}
Expand Down
21 changes: 2 additions & 19 deletions ogre2/src/Ogre2MeshFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
/// \brief Private data for the Ogre2MeshFactory class
class gz::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<MaterialPtr> materialCache;
};

/// \brief Private data for the Ogre2SubMeshStoreFactory class
Expand Down Expand Up @@ -91,22 +88,9 @@ void Ogre2MeshFactory::Clear()
}

//////////////////////////////////////////////////
void Ogre2MeshFactory::ClearMaterialsCache(const std::string &_name)
void Ogre2MeshFactory::ClearMaterialsCache(const std::string &)
{
auto it = this->dataPtr->materialCache.begin();
for (auto &mat : this->dataPtr->materialCache)
{
std::string matName = mat->Name();
std::string textureName = mat->Texture();
if (textureName == _name)
{
this->scene->UnregisterMaterial(matName);
break;
}
++it;
}
if (it != this->dataPtr->materialCache.end())
this->dataPtr->materialCache.erase(it);
// no-op
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -501,7 +485,6 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc)
if (material)
{
mat->CopyFrom(*material);
this->dataPtr->materialCache.push_back(mat);
}
else
{
Expand Down
Loading