From d443a37728da80876a51497c8be280fb57d51e70 Mon Sep 17 00:00:00 2001 From: johnche Date: Tue, 15 Oct 2024 11:25:19 +0800 Subject: [PATCH] =?UTF-8?q?[unity]=E9=87=8D=E6=9E=84=EF=BC=8C=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E5=AD=97=E6=9B=B4=E6=94=B9=EF=BC=8C=E7=94=B1?= =?UTF-8?q?=E4=BA=8E=E5=90=8E=E7=BB=AD=E9=9C=80=E8=A6=81=E4=BC=A0C#?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=EF=BC=8CP-Invoke=E6=94=B9=E4=B8=BAInternalCa?= =?UTF-8?q?ll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../puerts/xil2cpp/Puerts_il2cpp.cpp.txt | 40 ++++++++++--------- .../core/upm/Runtime/Src/IL2Cpp/JsEnv.cs | 4 +- .../Runtime/Src/IL2Cpp/Native/NativeAPI.cs | 14 +++++-- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/unity/Assets/core/upm/Editor/Resources/puerts/xil2cpp/Puerts_il2cpp.cpp.txt b/unity/Assets/core/upm/Editor/Resources/puerts/xil2cpp/Puerts_il2cpp.cpp.txt index 536f18f32f..efdbf75039 100644 --- a/unity/Assets/core/upm/Editor/Resources/puerts/xil2cpp/Puerts_il2cpp.cpp.txt +++ b/unity/Assets/core/upm/Editor/Resources/puerts/xil2cpp/Puerts_il2cpp.cpp.txt @@ -1897,6 +1897,25 @@ struct ScriptObjectsRefsMgr } }; +puerts::ScriptObjectsRefsMgr* InitialPapiEnvRef(pesapi_env_ref envRef) +{ + puerts::AutoValueScope ValueScope(envRef); + auto env = pesapi_get_env_from_ref(envRef); + auto mgr = new puerts::ScriptObjectsRefsMgr(envRef); + pesapi_set_env_private(env, mgr); + return mgr; +} + +void CleanupPapiEnvRef(pesapi_env_ref envRef) +{ + puerts::AutoValueScope ValueScope(envRef); + auto env = pesapi_get_env_from_ref(envRef); + auto scriptObjectsRefsMgr = (puerts::ScriptObjectsRefsMgr*)pesapi_get_env_private(env); + scriptObjectsRefsMgr->CleanupPendingKillScriptObjects(); + delete scriptObjectsRefsMgr; + pesapi_release_env_ref(envRef); +} + } #ifdef __cplusplus @@ -1921,29 +1940,12 @@ void InitialPuerts(pesapi_func_ptr* func_array) InternalCalls::Add("PuertsIl2cpp.NativeAPI::SetObjectToGlobal(System.IntPtr,System.String,System.Object)", (Il2CppMethodPointer)puerts::SetObjectToGlobal); InternalCalls::Add("PuertsIl2cpp.NativeAPI::TypeIdToType(System.IntPtr)", (Il2CppMethodPointer)puerts::TypeIdToType); InternalCalls::Add("PuertsIl2cpp.NativeAPI::GetModuleExecutor(System.IntPtr,System.Type)", (Il2CppMethodPointer)puerts::GetModuleExecutor); + InternalCalls::Add("PuertsIl2cpp.NativeAPI::InitialPapiEnvRef(System.IntPtr)", (Il2CppMethodPointer)puerts::InitialPapiEnvRef); + InternalCalls::Add("PuertsIl2cpp.NativeAPI::CleanupPapiEnvRef(System.IntPtr)", (Il2CppMethodPointer)puerts::CleanupPapiEnvRef); InternalCalls::Add("Puerts.JSObject::GetJSObjectValue(System.String,System.Type)", (Il2CppMethodPointer)puerts::GetJSObjectValue); pesapi_init(func_array); } -puerts::ScriptObjectsRefsMgr* CreateScriptObjectsRefsManager(pesapi_env_ref envRef) -{ - puerts::AutoValueScope ValueScope(envRef); - auto env = pesapi_get_env_from_ref(envRef); - auto mgr = new puerts::ScriptObjectsRefsMgr(envRef); - pesapi_set_env_private(env, mgr); - return mgr; -} - -void DestroyPapiEnvRefAndScriptObjectsRefsManager(pesapi_env_ref envRef) -{ - puerts::AutoValueScope ValueScope(envRef); - auto env = pesapi_get_env_from_ref(envRef); - auto scriptObjectsRefsMgr = (puerts::ScriptObjectsRefsMgr*)pesapi_get_env_private(env); - scriptObjectsRefsMgr->CleanupPendingKillScriptObjects(); - delete scriptObjectsRefsMgr; - pesapi_release_env_ref(envRef); -} - void AddPendingKillScriptObjects(puerts::ScriptObjectsRefsMgr* mgr, pesapi_value_ref valueRef) { pesapi_env_ref envRef = pesapi_get_ref_associated_env(valueRef); diff --git a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs index 8a16dfd121..3b1248586e 100644 --- a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs +++ b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs @@ -74,7 +74,7 @@ public JsEnv(ILoader loader, int debugPort = -1) nativeJsEnv = PuertsIl2cpp.NativeAPI.CreateNativeJSEnv(); nativePesapiEnv = PuertsIl2cpp.NativeAPI.GetPapiEnvRef(nativeJsEnv); - nativeScriptObjectsRefsMgr = PuertsIl2cpp.NativeAPI.CreateScriptObjectsRefsManager(nativePesapiEnv); + nativeScriptObjectsRefsMgr = PuertsIl2cpp.NativeAPI.InitialPapiEnvRef(nativePesapiEnv); //PuertsIl2cpp.NativeAPI.SetObjectPool(objectPool, typeof(PuertsIl2cpp.ObjectPool).GetMethod("Add")); //TODO: remove.... objectPoolAddMethodInfo = typeof(PuertsIl2cpp.ObjectPool).GetMethod("Add"); @@ -238,7 +238,7 @@ protected virtual void Dispose(bool dispose) lock (this) { if (disposed) return; - PuertsIl2cpp.NativeAPI.DestroyPapiEnvRefAndScriptObjectsRefsManager(nativePesapiEnv); + PuertsIl2cpp.NativeAPI.CleanupPapiEnvRef(nativePesapiEnv); PuertsIl2cpp.NativeAPI.DestroyNativeJSEnv(nativeJsEnv); disposed = true; } diff --git a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs index 1a13c5e2d8..237ab8732b 100644 --- a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs +++ b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs @@ -53,11 +53,17 @@ public class NativeAPI [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr GetPapiEnvRef(IntPtr jsEnv); - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CreateScriptObjectsRefsManager(IntPtr envRef); + [MethodImpl(MethodImplOptions.InternalCall)] + public static IntPtr InitialPapiEnvRef(IntPtr envRef) + { + throw new NotImplementedException(); + } - [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] - public static extern void DestroyPapiEnvRefAndScriptObjectsRefsManager(IntPtr envRef); + [MethodImpl(MethodImplOptions.InternalCall)] + public static void CleanupPapiEnvRef(IntPtr envRef) + { + throw new NotImplementedException(); + } [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr CreateCSharpTypeInfo(string name, IntPtr type_id, IntPtr super_type_id, IntPtr klass, bool isValueType, bool isDelegate, string delegateSignature);