-
Notifications
You must be signed in to change notification settings - Fork 446
NetworkBehaviour length safety checks can break synchronization #3335
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
Comments
Thanks for reporting this. Do you have logs of the error when things are breaking? |
These are the logs:
The NetworkList has around 80kb of data in it that needs syncing. When 'ReadField' is called in the network variable, it writes the whole 80kb of data into the stream writer. However, the reader can only read ushort (64kb) max data per variable message, leading to this issue. Specifically, the write command that tells the stream reader places the amount of bytes in the stream as the first value. However, this is a ushort. As we have more data than a ushort, it cannot write the full size of the incoming stream. I see two simple solutions to this problem. |
Thank you so much for all the information! This is definitely something that we need to fix |
@Mercury-Leo |
Description
If you have the flag `EnsureNetworkVariableLengthSafety' on, this can cause synchronization to break.
I have some very large network behaviours and this caused it to not work as intended when a new client joins and have to sync the full network object, there were no error that could indicate to this matter.
Reproduce Steps
ushort
bytesActual Outcome
Synchronization is broken.
Expected Outcome
Object is synced correctly between clients.
Environment
Additional Context
This is a mismatch between definitions.
In
NetworkMessageManager.cs
line 115public int FragmentedMessageMaxSize = int.MaxValue;
Max message size is defined as MaxInt.
In
NetworkBehaviour.cs
line 1262var varSize = (ushort)0;
varSize
gets cast toushort
.And if you have
ensureLengthSafety
on:if (NetworkVariableFields[j].CanClientRead(clientId)) { if (ensureLengthSafety) { reader.ReadValueSafe(out varSize); if (varSize == 0) { Debug.LogError($"[{name}][NetworkObjectId: {NetworkObjectId}][NetworkBehaviourId: {NetworkBehaviourId}][{NetworkVariableFields[j].Name}] Expected non-zero size readable NetworkVariable! (Skipping)"); continue; } readStartPos = reader.Position; } }
If the size is larger than a
ushort
(as it can get up toMax Int
), it will skip this and break.The text was updated successfully, but these errors were encountered: