Skip to content

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

Merged

Conversation

ShadauxCat
Copy link
Collaborator

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

  • Fixed: 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.

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary.

…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)
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity Mar 17, 2022

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a 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!

@0xFA11 0xFA11 enabled auto-merge (squash) March 18, 2022 15:32
Copy link
Contributor

@mattwalsh-unity mattwalsh-unity left a 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);
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@0xFA11 0xFA11 merged commit 8d211cf into develop Mar 18, 2022
@0xFA11 0xFA11 deleted the fix/networkvars_truncated_to_32k_when_lengthsafety_enabled branch March 18, 2022 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants