From 9d4534dfadaf0b207e20f6c16d3b1811d4aba856 Mon Sep 17 00:00:00 2001 From: KanouAo <54929340+KanouAo@users.noreply.github.com> Date: Thu, 6 Nov 2025 14:03:06 +0800 Subject: [PATCH] Update Table.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix memory alignment issue: calculate correct byte length (element count × element size) --- net/FlatBuffers/Table.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/FlatBuffers/Table.cs b/net/FlatBuffers/Table.cs index d6d9d09fb4c..f98f1ba7928 100644 --- a/net/FlatBuffers/Table.cs +++ b/net/FlatBuffers/Table.cs @@ -150,7 +150,9 @@ public T[] __vector_as_array(int offset) var pos = this.__vector(o); var len = this.__vector_len(o); - return bb.ToArray(pos, len); + // Fix memory alignment issue: calculate correct byte length (element count × element size) + var byteLen = len * System.Runtime.InteropServices.Marshal.SizeOf(); + return bb.ToArray(pos, byteLen); } // Initialize any Table-derived type to point to the union at the given offset.