Skip to content

Commit

Permalink
[unity]尝试去掉重复的PInvoke定义,看能否解决unity ci卡死
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Dec 18, 2024
1 parent d52cbf6 commit 8ff3cc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 55 deletions.
4 changes: 0 additions & 4 deletions unity/Assets/core/upm/Runtime/Src/Default/Native/PuertsDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using System.Runtime.InteropServices;
using System.Text;

#if !PUERTS_IL2CPP_OPTIMIZATION || !ENABLE_IL2CPP

namespace Puerts
{
#pragma warning disable 414
Expand Down Expand Up @@ -647,5 +645,3 @@ public static string GetJSStackTrace(IntPtr isolate)
}
}
}

#endif
18 changes: 9 additions & 9 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public JsEnv(ILoader loader, int debugPort = -1)
Puerts.NativeAPI.SetGlobalType_ArrayBuffer(typeof(ArrayBuffer));
Puerts.NativeAPI.SetGlobalType_JSObject(typeof(JSObject));

nativeJsEnv = Puerts.NativeAPI.CreateJSEngine(0);
nativeJsEnv = Puerts.PuertsDLL.CreateJSEngine(0);
nativePesapiEnv = Puerts.NativeAPI.GetPapiEnvRef(nativeJsEnv);
var objectPoolType = typeof(PuertsIl2cpp.ObjectPool);
nativeScriptObjectsRefsMgr = Puerts.NativeAPI.InitialPapiEnvRef(apis, nativePesapiEnv, objectPool, objectPoolType.GetMethod("Add"), objectPoolType.GetMethod("Remove"));
Expand All @@ -102,17 +102,17 @@ public JsEnv(ILoader loader, int debugPort = -1)
}
#endif

if (Puerts.NativeAPI.GetLibBackend(nativeJsEnv) == 0)
if (Puerts.PuertsDLL.GetLibBackend(nativeJsEnv) == 0)
Backend = new BackendV8(this);
else if (Puerts.NativeAPI.GetLibBackend(nativeJsEnv) == 1)
else if (Puerts.PuertsDLL.GetLibBackend(nativeJsEnv) == 1)
Backend = new BackendNodeJS(this);
else if (Puerts.NativeAPI.GetLibBackend(nativeJsEnv) == 2)
else if (Puerts.PuertsDLL.GetLibBackend(nativeJsEnv) == 2)
Backend = new BackendQuickJS(this);

PuertsIl2cpp.ExtensionMethodInfo.LoadExtensionMethodInfo();

if (debugPort != -1) {
Puerts.NativeAPI.CreateInspector(nativeJsEnv, debugPort);
Puerts.PuertsDLL.CreateInspector(nativeJsEnv, debugPort);
}
string debugpath;
string context = loader.ReadFile("puerts/esm_bootstrap.cjs", out debugpath);
Expand Down Expand Up @@ -280,8 +280,8 @@ public JSObject ExecuteModule(string specifier)
public void Tick()
{
Puerts.NativeAPI.CleanupPendingKillScriptObjects(nativeScriptObjectsRefsMgr);
Puerts.NativeAPI.InspectorTick(nativeJsEnv);
Puerts.NativeAPI.LogicTick(nativeJsEnv);
Puerts.PuertsDLL.InspectorTick(nativeJsEnv);
Puerts.PuertsDLL.LogicTick(nativeJsEnv);
if (TickHandler != null) TickHandler();
}

Expand All @@ -291,7 +291,7 @@ public void WaitDebugger()
#if THREAD_SAFE
lock(this) {
#endif
while (!Puerts.NativeAPI.InspectorTick(nativeJsEnv)) { }
while (!Puerts.PuertsDLL.InspectorTick(nativeJsEnv)) { }
#if THREAD_SAFE
}
#endif
Expand Down Expand Up @@ -325,7 +325,7 @@ protected virtual void Dispose(bool dispose)
{
if (disposed) return;
Puerts.NativeAPI.CleanupPapiEnvRef(apis, nativePesapiEnv);
Puerts.NativeAPI.DestroyJSEngine(nativeJsEnv);
Puerts.PuertsDLL.DestroyJSEngine(nativeJsEnv);
Puerts.NativeAPI.DestroyJSEnvPrivate(nativeScriptObjectsRefsMgr);
nativeScriptObjectsRefsMgr = IntPtr.Zero;
disposed = true;
Expand Down
44 changes: 2 additions & 42 deletions unity/Assets/core/upm/Runtime/Src/IL2Cpp/Native/NativeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code package.
*/

#if UNITY_2020_1_OR_NEWER
#if PUERTS_IL2CPP_OPTIMIZATION && ENABLE_IL2CPP

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
Expand All @@ -16,17 +13,6 @@

namespace Puerts
{
#pragma warning disable 414
public class MonoPInvokeCallbackAttribute : System.Attribute
{
private Type type;
public MonoPInvokeCallbackAttribute(Type t)
{
type = t;
}
}
#pragma warning restore 414

public class NativeAPI
{
#if (UNITY_IPHONE || UNITY_TVOS || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR
Expand All @@ -38,15 +24,6 @@ public class NativeAPI
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
public static extern void InitialPuerts(IntPtr PesapiImpl);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int GetLibBackend(IntPtr isolate);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateJSEngine(int backendType);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyJSEngine(IntPtr isolate);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr GetRegsterApi();

Expand Down Expand Up @@ -92,19 +69,8 @@ public class NativeAPI
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
public static extern void CleanupPendingKillScriptObjects(IntPtr jsEnv);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void CreateInspector(IntPtr jsEnv, int port);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyInspector(IntPtr jsEnv);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern bool InspectorTick(IntPtr jsEnv);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern bool LogicTick(IntPtr jsEnv);

#if PUERTS_IL2CPP_OPTIMIZATION && ENABLE_IL2CPP

[MethodImpl(MethodImplOptions.InternalCall)]
public static IntPtr InitialPapiEnvRef(IntPtr api, IntPtr envRef, Object obj, MethodBase addMethodBase, MethodBase removeMethodBase)
{
Expand Down Expand Up @@ -223,9 +189,6 @@ public static void LogImpl(string msg)
}

public static LogCallback Log = LogImpl;

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetLogCallback(IntPtr log, IntPtr logWarning, IntPtr logError);

[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
public static extern void SetLogCallbackInternal(IntPtr log);
Expand All @@ -246,7 +209,7 @@ public static void SetLogCallback(LogCallback log, LogCallback logWarning, LogCa
{
//SetLogCallback(fn1);
SetLogCallbackInternal(fn1);
SetLogCallback(fn1, fn2, fn3);
PuertsDLL.SetLogCallback(fn1, fn2, fn3);
}
catch(DllNotFoundException)
{
Expand Down Expand Up @@ -441,6 +404,3 @@ public struct pesapi_ffi
public pesapi_set_env_private_func set_env_private;
}
}

#endif
#endif

0 comments on commit 8ff3cc7

Please sign in to comment.