Resolve issue with multithreading when trying to get a base type from Angelscript.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-08-22 11:16:42 +02:00
parent b5ea856443
commit 592552cb72
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 4 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#define PKMNLIB_ANGELSCRIPTRESOLVER_HPP #define PKMNLIB_ANGELSCRIPTRESOLVER_HPP
#include <CreatureLib/Battling/ScriptHandling/ScriptResolver.hpp> #include <CreatureLib/Battling/ScriptHandling/ScriptResolver.hpp>
#include <mutex>
#include "../../../extern/angelscript_addons/scriptbuilder/scriptbuilder.h" #include "../../../extern/angelscript_addons/scriptbuilder/scriptbuilder.h"
#include "../../Battling/Library/BattleLibrary.hpp" #include "../../Battling/Library/BattleLibrary.hpp"
#include "AngelScriptEvolutionScript.hpp" #include "AngelScriptEvolutionScript.hpp"
@ -23,6 +24,8 @@ private:
ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>> _typeDatabase; ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*>> _typeDatabase;
ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _baseTypes; ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _baseTypes;
std::mutex _baseTypesLock;
ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _itemUseTypes; ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _itemUseTypes;
ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _evolutionTypes; ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _evolutionTypes;
ArbUt::Dictionary<const CreatureLib::Library::Item*, AngelScriptItemUseScript*> _itemUseScripts; ArbUt::Dictionary<const CreatureLib::Library::Item*, AngelScriptItemUseScript*> _itemUseScripts;
@ -92,6 +95,7 @@ public:
asITypeInfo* GetBaseType(const ArbUt::StringView& name) { asITypeInfo* GetBaseType(const ArbUt::StringView& name) {
asITypeInfo* t; asITypeInfo* t;
auto lock = std::lock_guard(_baseTypesLock);
auto v = _baseTypes.TryGet(name); auto v = _baseTypes.TryGet(name);
if (!v.has_value()) { if (!v.has_value()) {
t = _mainModule->GetTypeInfoByName(name.c_str()); t = _mainModule->GetTypeInfoByName(name.c_str());