MemoryPack icon indicating copy to clipboard operation
MemoryPack copied to clipboard

SerializationException: Sequence reached end, cannot provide more buffer

Open The64thGamer opened this issue 1 year ago • 2 comments

This error occurs on attempting to deserialize a class MemoryPackSerializer.Deserialize<Region>(FileAccess.GetFileAsBytes(finalPath))

MemoryPack.MemoryPackSerializationException: Sequence reached end, reader can not provide more buffer.
     at MemoryPack.MemoryPackSerializationException.ThrowSequenceReachedEnd()
     at MemoryPack.MemoryPackReader.GetNextSpan(Int32 sizeHint)
     at MemoryPack.Formatters.UnmanagedFormatter`1.Deserialize(MemoryPackReader& reader, T& value)
     at MemoryPack.Formatters.DictionaryFormatter`2.Deserialize(MemoryPackReader& reader, Dictionary`2& value)
     at Chunk.Deserialize(MemoryPackReader& reader, Chunk& value)
MemoryPack.Generator.MemoryPackGenerator/Chunk.MemoryPackFormatter.g.cs:line 112
     at Chunk.ChunkFormatter.Deserialize(MemoryPackReader& reader, Chunk& value) MemoryPack.Generator.MemoryPackGenerator/Chunk.MemoryPackFormatter.g.cs:line 226
     at MemoryPack.Formatters.DictionaryFormatter`2.Deserialize(MemoryPackReader& reader, Dictionary`2& value)
     at Region.Deserialize(MemoryPackReader& reader, Region& value)
MemoryPack.Generator.MemoryPackGenerator/Region.MemoryPackFormatter.g.cs:line 102
     at Region.RegionFormatter.Deserialize(MemoryPackReader& reader, Region& value) MemoryPack.Generator.MemoryPackGenerator/Region.MemoryPackFormatter.g.cs:line 202
     at MemoryPack.MemoryPackSerializer.Deserialize[T](ReadOnlySpan`1 buffer, T& value, MemoryPackSerializerOptions options)
     at MemoryPack.MemoryPackSerializer.Deserialize[T](ReadOnlySpan`1 buffer, MemoryPackSerializerOptions options)

Classes

[MemoryPackable]
public partial class Region
{
	public int positionX;
	public int positionY;
	public int positionZ;
	public Dictionary<Godot.Vector3,Chunk> chunks;
}
[MemoryPackable]
public partial class Chunk
{
	public bool hasGeneratedBorders;
	public int positionX;
	public int positionY;
	public int positionZ;
	public List<Brush> brushes;
	public Dictionary<ByteVector3, int> brushBBPositions;
}
[MemoryPackable]
public partial class ByteVector3
{
	public byte x,y,z;

	public override bool Equals(object obj)
    {
        // If the object is null, return false.
        if (obj == null || GetType() != obj.GetType())
        {
            return false;
        }

        // Cast the object to ByteVector3 to compare values.
        ByteVector3 other = (ByteVector3)obj;
        
        // Check if all components are equal.
        return x == other.x && y == other.y && z == other.z;
    }
    public override int GetHashCode()
    {
		return System.HashCode.Combine(x,y,z);
	}
}
[MemoryPackable]
public partial class Brush
{
	public byte[] vertices;
	public uint[] textures = new uint[]{ 0, 0, 0, 0, 0, 0 };
	public bool hiddenFlag;
	public bool borderFlag;
}

The typical file sizes of these deserialized Region files are around 35mb as the List<Brush> variable usually has around 3000 entries, and a few hundred Chunk classes are in each Region class. Also notable is that the Vector3 in Region is of Godot.Vector3 and not System.Vector3, I'm not sure if that is interfering with serialization at all.

The64thGamer avatar Apr 21 '24 20:04 The64thGamer

Could you provide the reproducible code or the data itself?

neuecc avatar Apr 30 '24 03:04 neuecc

I have the same error that happend on SlimFaas https://github.com/AxaFrance/SlimFaas @neuecc When I'am doing some stress test it happen. But I cannot isolate a case (or it will be very hard to find out, I have to think how)

guillaume-chervet avatar Jun 08 '24 19:06 guillaume-chervet

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Dec 06 '24 00:12 github-actions[bot]

important to investigate more

neuecc avatar Dec 06 '24 01:12 neuecc

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 05 '25 00:06 github-actions[bot]