From 0cd47744cbfba939ddd6e3a8041b4187cf994d68 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Wed, 9 Jun 2021 08:50:07 +0200 Subject: [PATCH] fix crash when saving mesh with texture without changing txtname --- src/common/ml_document/mesh_model.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common/ml_document/mesh_model.cpp b/src/common/ml_document/mesh_model.cpp index 4fd20df63..a16402852 100644 --- a/src/common/ml_document/mesh_model.cpp +++ b/src/common/ml_document/mesh_model.cpp @@ -175,13 +175,15 @@ void MeshModel::changeTextureName( const std::string& oldName, std::string newName) { - auto mit = textures.find(oldName); - auto tit = std::find(cm.textures.begin(), cm.textures.end(), oldName); - if (mit != textures.end() && tit != cm.textures.end()){ - *tit = newName; + if (oldName != newName) { + auto mit = textures.find(oldName); + auto tit = std::find(cm.textures.begin(), cm.textures.end(), oldName); + if (mit != textures.end() && tit != cm.textures.end()){ + *tit = newName; - textures[newName] = mit->second; - textures.erase(mit); + textures[newName] = mit->second; + textures.erase(mit); + } } }