Added mutex to resource manager cache reading to avoid a potential race condition. We hope this is the actual bug we saw.

This commit is contained in:
2016-02-04 11:53:11 +01:00
parent bd2da7bc9f
commit c87e4d4fd6
+10 -7
View File
@@ -200,13 +200,16 @@ static T* ResourceManager::Load(const std::string& resourceName, Resource* paren
} }
//If resource has already been cached and completely loaded. //If resource has already been cached and completely loaded.
it = m_ResourceCache.find(cacheKey); {
if (it != m_ResourceCache.end()) { boost::lock_guard<decltype(m_Mutex)> guard(m_Mutex);
if (it->second != nullptr) { it = m_ResourceCache.find(cacheKey);
return static_cast<T*>(it->second); if (it != m_ResourceCache.end()) {
} else { if (it->second != nullptr) {
//Don't return null on failure, exception instead. return static_cast<T*>(it->second);
throw Resource::FailedLoadingException(); } else {
//Don't return null on failure, exception instead.
throw Resource::FailedLoadingException();
}
} }
} }