Skip to content

Commit 599df0e

Browse files
avoitishinXottab-DUTY
authored andcommitted
* 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
1 parent 713a513 commit 599df0e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/xrGame/ui/UITextureMaster.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "uiabstract.h"
1414
#include "xrUIXmlParser.h"
1515
#include "Include/xrRender/UIShader.h"
16+
#include <iostream>
1617

1718
xr_map<shared_str, TEX_INFO> CUITextureMaster::m_textures;
1819
xr_map<sh_pair, ui_shader> CUITextureMaster::m_shaders;
@@ -50,7 +51,15 @@ void CUITextureMaster::ParseShTexInfo(LPCSTR xml_file)
5051
info.rect.y1 = xml.ReadAttribFlt(node, "texture", i, "y");
5152
info.rect.y2 = xml.ReadAttribFlt(node, "texture", i, "height") + info.rect.y1;
5253
shared_str id = xml.ReadAttrib(node, "texture", i, "id");
53-
m_textures.insert(std::make_pair(id, info));
54+
/* 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.
55+
/* Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair */
56+
/* 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 */
57+
if (m_textures.find(id) == m_textures.end())
58+
m_textures.emplace(id, info);
59+
else
60+
m_textures[id] = info;
61+
/* avo: end */
62+
//m_textures.insert(mk_pair(id,info)); // original GSC insert call
5463
}
5564

5665
xml.SetLocalRoot(root_node);

0 commit comments

Comments
 (0)