From ab41cd014462835e33c22f56e137602257763736 Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 30 Jun 2025 12:12:02 +0800 Subject: [PATCH] [fix] fix the bug that not collect struct in calli and extern method signature in generating MethodBridge. --- Editor/MethodBridge/Generator.cs | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Editor/MethodBridge/Generator.cs b/Editor/MethodBridge/Generator.cs index 185f05e..211dcbd 100644 --- a/Editor/MethodBridge/Generator.cs +++ b/Editor/MethodBridge/Generator.cs @@ -287,6 +287,7 @@ namespace HybridCLR.Editor.MethodBridge CollectStructDefs(_managed2NativeMethodList0, structTypeSet); CollectStructDefs(_native2ManagedMethodList0, structTypeSet); CollectStructDefs(_adjustThunkMethodList0, structTypeSet); + CollectStructDefs(_originalCalliMethodSignatures.Select(m => m.MethodSig).ToList(), structTypeSet); _structTypes0 = structTypeSet.ToList(); _structTypes0.Sort((a, b) => a.TypeId - b.TypeId); @@ -829,6 +830,38 @@ const ReversePInvokeMethodData hybridclr::interpreter::g_reversePInvokeMethodStu } + private void CollectStructDefs(List methods, HashSet structTypes) + { + ICorLibTypes corLibTypes = _genericMethods[0].Method.Module.CorLibTypes; + + foreach (var method in methods) + { + foreach (var paramInfo in method.Params) + { + var paramType = GetSharedTypeInfo(MetaUtil.ToShareTypeSig(corLibTypes, paramInfo)); + if (paramType.IsStruct) + { + structTypes.Add(paramType); + if (paramType.Klass.ContainsGenericParameter) + { + throw new Exception($"[CollectStructDefs] method:{method} type:{paramType.Klass} contains generic parameter"); + } + } + + } + var returnType = GetSharedTypeInfo(MetaUtil.ToShareTypeSig(corLibTypes, method.RetType)); + if (returnType.IsStruct) + { + structTypes.Add(returnType); + if (returnType.Klass.ContainsGenericParameter) + { + throw new Exception($"[CollectStructDefs] method:{method} type:{returnType.Klass} contains generic parameter"); + } + } + } + + } + class FieldInfo { public FieldDef field;