Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialisation Bug #124

Closed
eeetem opened this issue Dec 5, 2023 · 1 comment
Closed

Serialisation Bug #124

eeetem opened this issue Dec 5, 2023 · 1 comment
Labels
Bug Something isn't working

Comments

@eeetem
Copy link

eeetem commented Dec 5, 2023

After migrating to 2.1.1 version from 2.0.0 there's an issue when it comes to deserialising integers

for (int i = 0; i < 10; i++)
{
	Console.WriteLine(i);
	Data d = new Data();
	d.str = Random.Shared.Next().ToString();
	d.num = Random.Shared.Next();

	Message message = Message.Create();
	message.AddSerializable(d);
	var d2 = message.GetSerializable<Data>();

	message.Release();
		
	if (!d.Equals(d2))
	{
		Console.WriteLine(d);
		Console.WriteLine(d2);
		throw new Exception("not equal!");
	}
}
	


public struct Data : IMessageSerializable
{
	public int num = -1;
	public string str = "";

	public Data()
	{
	}

	public override string ToString()
	{
		return $"{nameof(num)}: {num}, {nameof(str)}: {str}";
	}
	

	public void Serialize(Message message)
	{
		message.AddString(str);
		message.AddInt(num);

	}

	public void Deserialize(Message message)
	{
		str = message.GetString();
		num = message.GetInt();
	}

}

This code works perfectly fine on 2.0.0.
while running it on 2.1.1 on the second iteration of the loop for whatever reason the integer gets deserialsed incorrectly.

The issue appears to be related to message pooling since removing message.release() "fixes" the issue.

@tom-weiland tom-weiland added the Bug Something isn't working label Dec 9, 2023
@tom-weiland
Copy link
Collaborator

This is happening because AddBytes (which AddString calls internally) doesn't properly reset data segments before writing when writeBit % BitsPerByte == 0.

xzippyzachx added a commit that referenced this issue Dec 10, 2023
xzippyzachx added a commit that referenced this issue Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants