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:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user