The open source OpenXR runtime

u/var: Protect tracker access with a mutex.

Solves a race condition that may crash the debug gui if objects are removed using u_var_remove_root

+8
+8
src/xrt/auxiliary/util/u_var.cpp
··· 14 14 #include <sstream> 15 15 #include <vector> 16 16 #include <unordered_map> 17 + #include <mutex> 17 18 18 19 19 20 namespace xrt::auxiliary::util { ··· 54 55 public: 55 56 std::unordered_map<std::string, uint32_t> counters = {}; 56 57 std::unordered_map<ptrdiff_t, Obj> map = {}; 58 + std::mutex mutex = {}; 57 59 bool on = false; 58 60 bool tested = false; 59 61 ··· 129 131 if (!get_on()) { 130 132 return; 131 133 } 134 + 135 + std::unique_lock<std::mutex> lock(gTracker.mutex); 132 136 133 137 auto name = std::string(c_name); 134 138 auto raw_name = name; ··· 157 161 return; 158 162 } 159 163 164 + std::unique_lock<std::mutex> lock(gTracker.mutex); 165 + 160 166 auto s = gTracker.map.find((ptrdiff_t)root); 161 167 if (s == gTracker.map.end()) { 162 168 return; ··· 171 177 if (!get_on()) { 172 178 return; 173 179 } 180 + 181 + std::unique_lock<std::mutex> lock(gTracker.mutex); 174 182 175 183 std::vector<Obj *> tmp; 176 184 tmp.reserve(gTracker.map.size());