-
Notifications
You must be signed in to change notification settings - Fork 450
fix: Fixed NetworkVariables being truncated to short.MaxValue when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. #1811
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
Conversation
…tworkConfig.EnsureNetworkVariableLengthSafety is enabled. In the process it was discovered that FRAGMENTED_MESSAGE_MAX_SIZE was actually larger than BytePacker.WriteValueBitPacked can support, so that was reduced to the actual correct max value.
@@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen | |||
- Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780) | |||
- Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779) | |||
- Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777) | |||
- Network variable updates are no longer limited to 32,768 bytes when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled. The limits are now determined by what the transport can send in a message. (#1811) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit-pick)
Could you update your entry to this: "- Fixed network..." and move this entry to the top of the list so we keep a descending order on the PR numbers?
@@ -56,7 +56,7 @@ public void Serialize(FastBufferWriter writer) | |||
{ | |||
if (!shouldWrite) | |||
{ | |||
writer.WriteValueSafe((ushort)0); | |||
BytePacker.WriteValueBitPacked(writer, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😻
|
||
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety) | ||
{ | ||
m_ReceivedNetworkVariableData.ReadValueSafe(out varSize); | ||
ByteUnpacker.ReadValueBitPacked(m_ReceivedNetworkVariableData, out varSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😻
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void WriteValueBitPacked<T>(FastBufferWriter writer, T value) where T: unmanaged => writer.WriteValueSafe(value); | ||
#else | ||
|
||
public const ushort BitPackedUshortMax = (1 << 15) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the minor changelog update, it looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with one comment
var tempWriter = new FastBufferWriter(MessagingSystem.NON_FRAGMENTED_MESSAGE_MAX_SIZE, Allocator.Temp, short.MaxValue); | ||
networkVariable.WriteDelta(tempWriter); | ||
var tempWriter = new FastBufferWriter(MessagingSystem.NON_FRAGMENTED_MESSAGE_MAX_SIZE, Allocator.Temp, MessagingSystem.FRAGMENTED_MESSAGE_MAX_SIZE); | ||
NetworkBehaviour.NetworkVariableFields[i].WriteDelta(tempWriter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, can still use the networkVariable
temporary here. More consistent if we create the temporary to use it throughout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was actually a merge thing. That local variable was introduced in another change that was made to develop while I was working on this and the merge naturally didn't update this line. I'll update it.
Fixed NetworkVariables being truncated to short.MaxValue when NetworkConfig.EnsureNetworkVariableLengthSafety is enabled.
In the process it was discovered that FRAGMENTED_MESSAGE_MAX_SIZE was actually larger than BytePacker.WriteValueBitPacked can support, so that was reduced to the actual correct max value.
MTT-2434
Changelog
com.unity.netcode.gameobjects
Testing and Documentation