[fix] 修复桥接函数遍历收集签名时,未等遍历完就结束执行,导致生成的桥接文件不完整的bug

main
walon 2022-10-14 14:47:27 +08:00
parent 823877275c
commit e3095ccc01
8 changed files with 55 additions and 7 deletions

View File

@ -37,6 +37,7 @@ namespace HybridCLR.Editor.Meta
{ {
return typeSig; return typeSig;
} }
typeSig = typeSig.RemovePinnedAndModifiers();
switch (typeSig.ElementType) switch (typeSig.ElementType)
{ {
case ElementType.Ptr: return new PtrSig(Resolve(typeSig.Next)); case ElementType.Ptr: return new PtrSig(Resolve(typeSig.Next));
@ -64,7 +65,7 @@ namespace HybridCLR.Editor.Meta
{ {
GenericMVar genericVar = (GenericMVar)typeSig; GenericMVar genericVar = (GenericMVar)typeSig;
var newSig = Resolve(methodArgsStack, genericVar.Number, true); var newSig = Resolve(methodArgsStack, genericVar.Number, true);
if (newSig is null) if (newSig == null)
{ {
throw new Exception(); throw new Exception();
} }

View File

@ -42,6 +42,11 @@ namespace HybridCLR.Editor.Meta
return _hashCode; return _hashCode;
} }
public override string ToString()
{
return $"{Method}|{string.Join(",", (IEnumerable<TypeSig>)KlassInst ?? Array.Empty<TypeSig>())}|{string.Join(",", (IEnumerable<TypeSig>)MethodInst ?? Array.Empty<TypeSig>())}";
}
private int ComputHashCode() private int ComputHashCode()
{ {
int hash = MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(Method); int hash = MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(Method);

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class UnityAOTAssemblyResolver : IAssemblyResolver
{
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
//
var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot/{assemblyName}.dll";
if (File.Exists(assemblyFile))
{
Debug.Log($"UnityAOTAssemblyResolver.ResolveAssembly:{assemblyFile}");
return assemblyFile;
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 029bc0368e1ada342aa29a18d4fae879
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -30,7 +30,7 @@ namespace HybridCLR.Editor.Meta
{ {
if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll)) if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll))
{ {
Debug.Log($"plugin:{dll}"); Debug.Log($"UnityPluginAssemblyResolver.ResolveAssembly:{dll}");
return dll; return dll;
} }
} }

View File

@ -29,7 +29,7 @@ namespace HybridCLR.Editor
return typeSig; return typeSig;
} }
var a = typeSig.RemovePinnedAndModifiers(); var a = typeSig.RemovePinnedAndModifiers();
switch (typeSig.ElementType) switch (a.ElementType)
{ {
case ElementType.Void: return corTypes.Void; case ElementType.Void: return corTypes.Void;
case ElementType.Boolean: return corTypes.Byte; case ElementType.Boolean: return corTypes.Byte;
@ -87,6 +87,7 @@ namespace HybridCLR.Editor
return new CombinedAssemblyResolver(new PathAssemblyResolver( return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)), SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)),
new UnityPluginAssemblyResolver(), new UnityPluginAssemblyResolver(),
new UnityAOTAssemblyResolver(),
new UnityEditorAssemblyResolver()); new UnityEditorAssemblyResolver());
} }
} }

View File

@ -118,7 +118,7 @@ namespace HybridCLR.Editor.MethodBridge
} }
foreach (var method in typeDef.Methods) foreach (var method in typeDef.Methods)
{ {
// 对于带泛型的参数,统泛型共享为object // 对于带泛型的参数,统泛型共享为object
_notGenericMethods.Add(method); _notGenericMethods.Add(method);
} }
} }
@ -182,10 +182,10 @@ namespace HybridCLR.Editor.MethodBridge
_newMethods = temp; _newMethods = temp;
_newMethods.Clear(); _newMethods.Clear();
Task.WhenAll(_processingMethods.Select(method => Task.Run(() => Task.WaitAll(_processingMethods.Select(method => Task.Run(() =>
{ {
_methodReferenceAnalyzer.WalkMethod(method.Method, method.KlassInst, method.MethodInst); _methodReferenceAnalyzer.WalkMethod(method.Method, method.KlassInst, method.MethodInst);
}))); })).ToArray());
Debug.Log($"iteration:[{i}] allMethods:{_notGenericMethods.Count} genericClass:{_genericTypes.Count} genericMethods:{_genericMethods.Count} newMethods:{_newMethods.Count}"); Debug.Log($"iteration:[{i}] allMethods:{_notGenericMethods.Count} genericClass:{_genericTypes.Count} genericMethods:{_genericMethods.Count} newMethods:{_newMethods.Count}");
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "com.focus-creative-games.hybridclr_unity", "name": "com.focus-creative-games.hybridclr_unity",
"version": "0.4.0", "version": "0.4.1",
"displayName": "HybridCLR", "displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime", "category": "Runtime",