Skip to content

Commit

Permalink
Use mutex lock to avoid race condition when loading textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegeri authored and eagleivg committed Nov 6, 2018
1 parent d52cbc4 commit e8134d7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/xrUICore/XML/UITextureMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "xrUIXmlParser.h"
#include "Include/xrRender/UIShader.h"
#include <iostream>
#include <mutex>

xr_map<shared_str, TEX_INFO> CUITextureMaster::m_textures;
xr_map<sh_pair, ui_shader> CUITextureMaster::m_shaders;
Expand Down Expand Up @@ -54,6 +55,8 @@ void CUITextureMaster::ParseShTexInfo(pcstr path, pcstr xml_file)
/* 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 */
static std::mutex new_texture_mutex;
std::scoped_lock new_texture_lock (new_texture_mutex);
if (m_textures.find(id) == m_textures.end())
m_textures.emplace(id, info);
else
Expand Down

0 comments on commit e8134d7

Please sign in to comment.