From 599df0efbfba7946639e8796dcfe4126f0a47c98 Mon Sep 17 00:00:00 2001 From: Andrey Voitishin Date: Mon, 22 Dec 2014 12:19:11 -0500 Subject: [PATCH] * Fix: values were not updated (silently skipped) when same key is encountered more than once. This is how std::map is designed. Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair. Note that xxx.insert(mk_pair(v1,v2)) pattern is used extensively throughout solution so there is a good potential for other bug fixes/improvements --- src/xrGame/ui/UITextureMaster.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/xrGame/ui/UITextureMaster.cpp b/src/xrGame/ui/UITextureMaster.cpp index b139caaf8f4..7010be55c64 100644 --- a/src/xrGame/ui/UITextureMaster.cpp +++ b/src/xrGame/ui/UITextureMaster.cpp @@ -13,6 +13,7 @@ #include "uiabstract.h" #include "xrUIXmlParser.h" #include "Include/xrRender/UIShader.h" +#include xr_map CUITextureMaster::m_textures; xr_map CUITextureMaster::m_shaders; @@ -50,7 +51,15 @@ void CUITextureMaster::ParseShTexInfo(LPCSTR xml_file) info.rect.y1 = xml.ReadAttribFlt(node, "texture", i, "y"); info.rect.y2 = xml.ReadAttribFlt(node, "texture", i, "height") + info.rect.y1; shared_str id = xml.ReadAttrib(node, "texture", i, "id"); - m_textures.insert(std::make_pair(id, info)); + /* avo: fix issue when values were not updated (silently skipped) when same key is encountered more than once. This is how std::map is designed. + /* Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair */ + /* XXX: avo: note that xxx.insert(mk_pair(v1,v2)) pattern is used extensively throughout solution so there is a good potential for other bug fixes/improvements */ + if (m_textures.find(id) == m_textures.end()) + m_textures.emplace(id, info); + else + m_textures[id] = info; + /* avo: end */ + //m_textures.insert(mk_pair(id,info)); // original GSC insert call } xml.SetLocalRoot(root_node);