Skip to content

Commit e8134d7

Browse files
Zegerieagleivg
authored andcommitted
Use mutex lock to avoid race condition when loading textures
1 parent d52cbc4 commit e8134d7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/xrUICore/XML/UITextureMaster.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "xrUIXmlParser.h"
1515
#include "Include/xrRender/UIShader.h"
1616
#include <iostream>
17+
#include <mutex>
1718

1819
xr_map<shared_str, TEX_INFO> CUITextureMaster::m_textures;
1920
xr_map<sh_pair, ui_shader> CUITextureMaster::m_shaders;
@@ -54,6 +55,8 @@ void CUITextureMaster::ParseShTexInfo(pcstr path, pcstr xml_file)
5455
/* 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.
5556
/* Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair */
5657
/* 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 */
58+
static std::mutex new_texture_mutex;
59+
std::scoped_lock new_texture_lock (new_texture_mutex);
5760
if (m_textures.find(id) == m_textures.end())
5861
m_textures.emplace(id, info);
5962
else

0 commit comments

Comments
 (0)