From f7c08691c4ac4ca4f8259dfaa3049b7161fd7903 Mon Sep 17 00:00:00 2001 From: johnche Date: Fri, 13 Sep 2024 17:11:42 +0800 Subject: [PATCH] =?UTF-8?q?[unity]=E7=A1=AE=E4=BF=9DHandleScope=E5=89=8D?= =?UTF-8?q?=E9=83=BD=E5=8A=A0locker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unity/native_src/Src/BackendEnv.cpp | 9 +++++++++ unity/native_src_il2cpp/Src/CppObjectMapper.cpp | 3 +++ unity/native_src_il2cpp/Src/Puerts.cpp | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/unity/native_src/Src/BackendEnv.cpp b/unity/native_src/Src/BackendEnv.cpp index 5306516dcd..072fc4073b 100644 --- a/unity/native_src/Src/BackendEnv.cpp +++ b/unity/native_src/Src/BackendEnv.cpp @@ -995,6 +995,9 @@ static void DoHostImportModuleDynamically(void* import_data_) v8::Isolate* isolate(import_data->isolate); auto backend_env = FBackendEnv::Get(isolate); +#ifdef THREAD_SAFE + v8::Locker Locker(isolate); +#endif v8::HandleScope handle_scope(isolate); v8::Local context = backend_env->MainContext.Get(isolate); v8::Context::Scope context_scope(context); @@ -1073,6 +1076,9 @@ v8::MaybeLocal esmodule::HostImportModuleDynamically( v8::Local referrer_name = referrer->GetResourceName(); #endif auto isolate = context->GetIsolate(); +#ifdef THREAD_SAFE + v8::Locker Locker(isolate); +#endif v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(context); v8::Local resolver; @@ -1112,6 +1118,9 @@ void esmodule::HostInitializeImportMetaObject(v8::Local Context, v8 std::string FBackendEnv::GetJSStackTrace() { v8::Isolate* Isolate = MainIsolate; +#ifdef THREAD_SAFE + v8::Locker Locker(Isolate); +#endif v8::HandleScope HandleScope(Isolate); v8::Local Context = MainContext.Get(Isolate); v8::Context::Scope ContextScope(Context); diff --git a/unity/native_src_il2cpp/Src/CppObjectMapper.cpp b/unity/native_src_il2cpp/Src/CppObjectMapper.cpp index 90616afe31..716a6c5f84 100644 --- a/unity/native_src_il2cpp/Src/CppObjectMapper.cpp +++ b/unity/native_src_il2cpp/Src/CppObjectMapper.cpp @@ -215,6 +215,9 @@ v8::Local FCppObjectMapper::GetTemplateOfClass(v8::Isolate { return v8::Local(); } +#ifdef THREAD_SAFE + v8::Locker Locker(Isolate); +#endif v8::EscapableHandleScope HandleScope(Isolate); auto Template = v8::FunctionTemplate::New( diff --git a/unity/native_src_il2cpp/Src/Puerts.cpp b/unity/native_src_il2cpp/Src/Puerts.cpp index d1e8997a83..06cec1049c 100644 --- a/unity/native_src_il2cpp/Src/Puerts.cpp +++ b/unity/native_src_il2cpp/Src/Puerts.cpp @@ -304,6 +304,9 @@ static v8::Value* GetModuleExecutor(v8::Context* env) static void* GetJSObjectValue(const PersistentObjectInfo* objectInfo, const char* key, const void* Typeid) { auto Isolate = objectInfo->EnvInfo->Isolate; +#ifdef THREAD_SAFE + v8::Locker Locker(Isolate); +#endif v8::Isolate::Scope Isolatescope(Isolate); v8::HandleScope HandleScope(Isolate); auto LocalContext = objectInfo->EnvInfo->Context.Get(Isolate); @@ -718,6 +721,9 @@ struct JSEnv auto Isolate = MainIsolate; +#ifdef THREAD_SAFE + v8::Locker Locker(Isolate); +#endif v8::Isolate::Scope Isolatescope(Isolate); v8::HandleScope HandleScope(Isolate);