Skip to content

fix: cast messagesize as uint (credit: kaen / #1592) #1686

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
merged 12 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

- Disallowed async keyword in RPCs (#1681)
- Fixed an issue where Alpha release versions of Unity (version 20202.2.0a5 and later) will not compile due to the UNet Transport no longer existing (#1678)
- Fixed messages larger than 64k being written with incorrectly truncated message size in header (#1686) (credit: @kaen)
- Fixed overloading RPC methods causing collisions and failing on IL2CPP targets. (#1694)
- Fixed spawn flow to propagate `IsSceneObject` down to children NetworkObjects, decouple implicit relationship between object spawning & `IsSceneObject` flag (#1685)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ internal unsafe int SendPreSerializedMessage<TMessageType>(in FastBufferWriter t

var header = new MessageHeader
{
MessageSize = (ushort)tmpSerializer.Length,
MessageSize = (uint)tmpSerializer.Length,
MessageType = m_MessageTypes[typeof(TMessageType)],
};
BytePacker.WriteValueBitPacked(headerSerializer, header.MessageType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace Unity.Netcode.RuntimeTests
{
public class NetworkObjectSpawnManyObjectsTests
{
// "many" in this case means enough to exceed a ushort_max message size written in the header
// 1500 is not a magic number except that it's big enough to trigger a failure
private const int k_SpawnedObjects = 1500;

[UnityTest]
// When this test fails it does so without an exception and will wait the default ~6 minutes
[Timeout(10000)]
public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived()
{
MultiInstanceHelpers.Create(1, out NetworkManager server, out NetworkManager[] clients);

// create prefab
var gameObject = new GameObject("TestObject");
var networkObject = gameObject.AddComponent<NetworkObject>();
MultiInstanceHelpers.MakeNetworkObjectTestPrefab(networkObject);

server.NetworkConfig.NetworkPrefabs.Add(new NetworkPrefab()
{
Prefab = gameObject
});

for (int i = 0; i < clients.Length; i++)
{
clients[i].NetworkConfig.NetworkPrefabs.Add(new NetworkPrefab()
{
Prefab = gameObject
});
}

MultiInstanceHelpers.Start(false, server, clients);

for (int i = 0; i < k_SpawnedObjects; i++)
{
NetworkObject serverObject = Object.Instantiate(gameObject).GetComponent<NetworkObject>();
serverObject.NetworkManagerOwner = server;
serverObject.Spawn();
}

// wait for connection on client side
yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.WaitForClientsConnected(clients, null, 10));

// wait for connection on server side
yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.WaitForClientConnectedToServer(server, null, 10));

// ensure all objects are replicated
Assert.AreEqual(k_SpawnedObjects, clients[0].SpawnManager.SpawnedObjectsList.Count);
MultiInstanceHelpers.Destroy();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.