[AssetHandler] Use mutex to synchronize DB_FXAH access

This commit is contained in:
momo5502 2016-12-19 19:41:29 +01:00
parent d8d67898f3
commit bac3f4cd44
2 changed files with 8 additions and 2 deletions

View File

@ -3,6 +3,7 @@
namespace Components
{
bool AssetHandler::BypassState = false;
std::recursive_mutex AssetHandler::BypassMutex;
std::map<Game::XAssetType, AssetHandler::IAsset*> AssetHandler::AssetInterfaces;
std::map<Game::XAssetType, wink::slot<AssetHandler::Callback>> AssetHandler::TypeCallbacks;
wink::signal<wink::slot<AssetHandler::RestrictCallback>> AssetHandler::RestrictSignal;
@ -54,6 +55,8 @@ namespace Components
if (filename)
{
std::lock_guard<std::recursive_mutex> _(AssetHandler::BypassMutex);
// Allow call DB_FindXAssetHeader within the hook
AssetHandler::BypassState = true;
@ -308,11 +311,13 @@ namespace Components
Game::XAssetHeader AssetHandler::FindOriginalAsset(Game::XAssetType type, const char* filename)
{
bool OriginalState = AssetHandler::BypassState;
std::lock_guard<std::recursive_mutex> _(AssetHandler::BypassMutex);
bool originalState = AssetHandler::BypassState;
AssetHandler::BypassState = true;
Game::XAssetHeader header = Game::DB_FindXAssetHeader(type, filename);
if(!OriginalState) AssetHandler::BypassState = false;
if(!originalState) AssetHandler::BypassState = false;
return header;
}

View File

@ -41,6 +41,7 @@ namespace Components
private:
static bool BypassState;
static std::recursive_mutex BypassMutex;
static std::map<std::string, Game::XAssetHeader> TemporaryAssets[Game::XAssetType::ASSET_TYPE_COUNT];