From 947b15e7d9cd6906f3b29aeb314229b534efe385 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 14 Dec 2022 10:21:31 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8DStructLayout=E4=B8=AD?= =?UTF-8?q?=E5=8F=AA=E6=8C=87=E5=AE=9ALayoutKind=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=97=B6=EF=BC=8Cstruct=E7=9A=84ClassLayout=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=EF=BC=8C=E8=AE=A1=E7=AE=97type=20size=E5=92=8Caligment?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/ABI/TypeCreatorBase.cs | 5 +++++ Editor/ABI/ValueTypeSizeAligmentCalculator.cs | 6 +++--- package.json | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Editor/ABI/TypeCreatorBase.cs b/Editor/ABI/TypeCreatorBase.cs index 54b3ffd..9c98490 100644 --- a/Editor/ABI/TypeCreatorBase.cs +++ b/Editor/ABI/TypeCreatorBase.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UnityEngine; namespace HybridCLR.Editor.ABI { @@ -74,6 +75,10 @@ namespace HybridCLR.Editor.ABI case ElementType.ValueType: { TypeDef typeDef = type.ToTypeDefOrRef().ResolveTypeDef(); + if (typeDef == null) + { + throw new Exception($"type:{type} 未能找到定义。请尝试 `HybridCLR/Genergate/LinkXml`,然后Build一次生成AOT dll,再重新生成桥接函数"); + } if (typeDef.IsEnum) { return CreateTypeInfo(typeDef.GetEnumUnderlyingType()); diff --git a/Editor/ABI/ValueTypeSizeAligmentCalculator.cs b/Editor/ABI/ValueTypeSizeAligmentCalculator.cs index 5162271..a97dd02 100644 --- a/Editor/ABI/ValueTypeSizeAligmentCalculator.cs +++ b/Editor/ABI/ValueTypeSizeAligmentCalculator.cs @@ -74,11 +74,11 @@ namespace HybridCLR.Editor.ABI { continue; } - if (sa != null && typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.ExplicitLayout)) + if (typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.ExplicitLayout)) { int offset = (int)field.FieldOffset.Value; totalSize = Math.Max(totalSize, offset + fs); - if (offset > sa.ClassSize) + if (sa != null && offset > sa.ClassSize) { useSLSize = false; } @@ -90,7 +90,7 @@ namespace HybridCLR.Editor.ABI totalSize = (totalSize + fa - 1) / fa * fa; } totalSize += fs; - if (sa != null && typeDef.Layout.HasFlag(dnlib.DotNet.TypeAttributes.SequentialLayout) && totalSize > sa.ClassSize) + if (sa != null && totalSize > sa.ClassSize) { useSLSize = false; } diff --git a/package.json b/package.json index 029349b..2ad77f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "1.1.12", + "version": "1.1.13", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",