flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

In C#. A bug where the array count must be a multiple of 4

Open KanouAo opened this issue 2 months ago • 3 comments

Image Image Image Image - In Table.cs , the __vector_as_array() method calls __vector_len() to get the number of elements in the vector - This element count is then directly passed as lenInBytes to ByteBuffer.ToArray(pos, len) - In ByteBuffer.ToArray() , the ConvertBytesToTs() method checks if lenInBytes is a multiple of the size of type T - When retrieving an int[] with 3 elements, the element count (3) is passed instead of the actual byte count (12), causing the alignment check to fail

KanouAo avatar Nov 06 '25 05:11 KanouAo

FlatBuffers version: 25.9.23 in windows.

KanouAo avatar Nov 06 '25 05:11 KanouAo

I create a pull just a line. https://github.com/google/flatbuffers/pull/8760/commits/ae99831dea3f66cf5771d9054468923954567497 var byteLen = len * System.Runtime.InteropServices.Marshal.SizeOf<T>(); return bb.ToArray<T>(pos, byteLen);

KanouAo avatar Nov 06 '25 06:11 KanouAo

This a critical defect that we run into. Our trimeshes (float3 arrays) are broken because of this bug.

I had to rollback to the previous version of flatbuffers

njannink avatar Dec 02 '25 17:12 njannink