From 075c224022d107a60715709c9662fe3b9fceb0f3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 19 Sep 2024 19:35:45 +0200 Subject: [PATCH] Fix C# structures memory packing to match C++ better #2709 --- Source/Engine/Animations/Curve.cs | 4 ++-- Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Animations/Curve.cs b/Source/Engine/Animations/Curve.cs index 1ff129b57..a0d911141 100644 --- a/Source/Engine/Animations/Curve.cs +++ b/Source/Engine/Animations/Curve.cs @@ -465,7 +465,7 @@ namespace FlaxEngine /// /// A single keyframe that can be injected into linear curve. /// - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = 2)] public struct Keyframe : IComparable, IComparable { /// @@ -720,7 +720,7 @@ namespace FlaxEngine /// /// A single keyframe that can be injected into Bezier curve. /// - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, Pack = 2)] public struct Keyframe : IComparable, IComparable { /// diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index eadd45fbc..0cb3c49bf 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -1542,7 +1542,7 @@ namespace Flax.Build.Bindings var structIndent = ""; if (buildData.Target != null & buildData.Target.IsEditor) structContents.Append(structIndent).AppendLine("[HideInEditor]"); - structContents.Append(structIndent).AppendLine("[StructLayout(LayoutKind.Sequential)]"); + structContents.Append(structIndent).AppendLine("[StructLayout(LayoutKind.Sequential, Pack = 2)]"); structContents.Append(structIndent).Append("public struct ").Append(structureInfo.Name).Append("Internal"); if (structureInfo.BaseType != null && structureInfo.IsPod) structContents.Append(" : ").Append(GenerateCSharpNativeToManaged(buildData, new TypeInfo { Type = structureInfo.BaseType.Name }, structureInfo));