Skip to content

Commit 0aace77

Browse files
committed
Merge branch 'develop' into feature/NetworkTransform-using-Netvars
* develop: fix: gracefully handle exceptions in an RPC invoke (#846) fix: Fixing utp license file for legal (#843) ci: enable standards check on UTP too (#837) refactor: NetworkBehaviour.NetworkObject no longer throws an exception (#838) fix: revert #830 (#840) test: converting the manual rpc tests over to an automated unit test (#830)
2 parents 673ac2f + c09fa57 commit 0aace77

File tree

13 files changed

+148
-117
lines changed

13 files changed

+148
-117
lines changed

com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ public NetworkObject NetworkObject
300300
m_NetworkObject = GetComponentInParent<NetworkObject>();
301301
}
302302

303-
if (m_NetworkObject == null)
303+
if (m_NetworkObject == null && NetworkLog.CurrentLogLevel <= LogLevel.Normal)
304304
{
305-
throw new NullReferenceException($"Could not get {nameof(NetworkObject)} for the {nameof(NetworkBehaviour)}. Are you missing a {nameof(NetworkObject)} component?");
305+
NetworkLog.LogWarning($"Could not get {nameof(NetworkObject)} for the {nameof(NetworkBehaviour)}. Are you missing a {nameof(NetworkObject)} component?");
306306
}
307307

308308
return m_NetworkObject;
@@ -312,18 +312,7 @@ public NetworkObject NetworkObject
312312
/// <summary>
313313
/// Gets whether or not this NetworkBehaviour instance has a NetworkObject owner.
314314
/// </summary>
315-
public bool HasNetworkObject
316-
{
317-
get
318-
{
319-
if (m_NetworkObject == null)
320-
{
321-
m_NetworkObject = GetComponentInParent<NetworkObject>();
322-
}
323-
324-
return m_NetworkObject != null;
325-
}
326-
}
315+
public bool HasNetworkObject => NetworkObject != null;
327316

328317
private NetworkObject m_NetworkObject = null;
329318

com.unity.multiplayer.mlapi/Runtime/Core/NetworkManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem, IProfilableTr
5656
internal NetworkTickSystem NetworkTickSystem { get; private set; }
5757

5858
internal SnapshotSystem SnapshotSystem { get; private set; }
59-
59+
6060
private NetworkPrefabHandler m_PrefabHandler;
6161
public NetworkPrefabHandler PrefabHandler
6262
{
6363
get
6464
{
65-
if(m_PrefabHandler == null)
65+
if (m_PrefabHandler == null)
6666
{
6767
m_PrefabHandler = new NetworkPrefabHandler();
6868
}
6969
return m_PrefabHandler;
70-
}
70+
}
7171
}
7272

7373
/// <summary>

com.unity.multiplayer.mlapi/Runtime/Messaging/RpcQueue/RpcQueueProcessor.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Unity.Profiling;
44
using MLAPI.Configuration;
55
using MLAPI.Profiling;
6+
using MLAPI.Logging;
7+
using UnityEngine;
68

79
namespace MLAPI.Messaging
810
{
@@ -60,7 +62,19 @@ public void ProcessReceiveQueue(NetworkUpdateStage currentStage, bool isTesting)
6062

6163
if (!isTesting)
6264
{
63-
m_NetworkManager.InvokeRpc(currentQueueItem);
65+
try
66+
{
67+
m_NetworkManager.InvokeRpc(currentQueueItem);
68+
}
69+
catch (Exception ex)
70+
{
71+
Debug.LogException(ex);
72+
73+
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
74+
{
75+
NetworkLog.LogWarning($"A {currentQueueItem.QueueItemType} threw an exception while executing! Please check Unity logs for more information.");
76+
}
77+
}
6478
}
6579

6680
ProfilerStatManager.RpcsQueueProc.Record();

com.unity.multiplayer.mlapi/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ internal void ServerDestroySpawnedSceneObjects()
484484
// within the NetworkSceneManager.SwitchScene method.
485485
SpawnedObjectsList.Remove(sobj);
486486
if (NetworkManager.PrefabHandler != null && NetworkManager.PrefabHandler.ContainsHandler(sobj))
487-
{
487+
{
488488
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(sobj);
489489
OnDestroyObject(sobj.NetworkObjectId, false);
490490
}
491491
else
492-
{
492+
{
493493
UnityEngine.Object.Destroy(sobj.gameObject);
494494
}
495495
}

com.unity.multiplayer.mlapi/Tests/Editor/NetworkBehaviourTests.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,15 @@ public void AccessNetworkObjectTest()
3333
var gameObject = new GameObject(nameof(AccessNetworkObjectTest));
3434
var networkBehaviour = gameObject.AddComponent<EmptyNetworkBehaviour>();
3535

36-
// TODO: Do we really want to throw here?
37-
// Future API change: return null
38-
Assert.Throws<NullReferenceException>(() =>
39-
{
40-
var x = networkBehaviour.NetworkObject;
41-
});
36+
Assert.That(networkBehaviour.NetworkObject, Is.Null);
4237

4338
var networkObject = gameObject.AddComponent<NetworkObject>();
4439

4540
Assert.That(networkBehaviour.NetworkObject, Is.EqualTo(networkObject));
4641

4742
Object.DestroyImmediate(networkObject);
4843

49-
// TODO: Do we really want to throw here?
50-
// Future API change: return null
51-
Assert.Throws<NullReferenceException>(() =>
52-
{
53-
var x = networkBehaviour.NetworkObject;
54-
});
44+
Assert.That(networkBehaviour.NetworkObject, Is.Null);
5545

5646
// Cleanup
5747
Object.DestroyImmediate(gameObject);

com.unity.multiplayer.mlapi/Tests/Runtime/ConnectionApproval.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ConnectionApprovalTests
1919
public void Setup()
2020
{
2121
// Create, instantiate, and host
22-
Assert.IsTrue(NetworkManagerHelper.StartNetworkManager(out _,NetworkManagerHelper.NetworkManagerOperatingMode.None));
22+
Assert.IsTrue(NetworkManagerHelper.StartNetworkManager(out _, NetworkManagerHelper.NetworkManagerOperatingMode.None));
2323
m_ValidationToken = Guid.NewGuid();
2424
}
2525

@@ -35,24 +35,24 @@ public IEnumerator ConnectionApproval()
3535

3636
var timeOut = Time.realtimeSinceStartup + 3.0f;
3737
var timedOut = false;
38-
while(!m_IsValidated)
38+
while (!m_IsValidated)
3939
{
4040
yield return new WaitForSeconds(0.01f);
41-
if(timeOut < Time.realtimeSinceStartup)
41+
if (timeOut < Time.realtimeSinceStartup)
4242
{
4343
timedOut = true;
4444
}
4545
}
4646

4747
//Make sure we didn't time out
4848
Assert.False(timedOut);
49-
Assert.True(m_IsValidated);
49+
Assert.True(m_IsValidated);
5050
}
5151

5252
private void NetworkManagerObject_ConnectionApprovalCallback(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback)
5353
{
5454
var stringGuid = Encoding.UTF8.GetString(connectionData);
55-
if(m_ValidationToken.ToString() == stringGuid)
55+
if (m_ValidationToken.ToString() == stringGuid)
5656
{
5757
m_IsValidated = true;
5858
}

com.unity.multiplayer.mlapi/Tests/Runtime/NetworkPrefabHandlerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class NetworkPrefabHandlerTests
2121
/// </summary>
2222
[Test]
2323
public void NetworkConfigInvalidNetworkPrefabTest()
24-
{
24+
{
2525
var testPrefabObjectName = "NetworkPrefabHandlerTestObject";
2626
Guid baseObjectID = NetworkManagerHelper.AddGameNetworkObject(testPrefabObjectName);
2727
NetworkObject baseObject = NetworkManagerHelper.InstantiatedNetworkObjects[baseObjectID];
@@ -37,7 +37,7 @@ public void NetworkConfigInvalidNetworkPrefabTest()
3737

3838
//Add a valid prefab
3939
NetworkManagerHelper.NetworkManagerObject.NetworkConfig.NetworkPrefabs.Add(validNetworkPrefab);
40-
var exceptionOccurred = false;
40+
var exceptionOccurred = false;
4141
try
4242
{
4343
NetworkManagerHelper.NetworkManagerObject.StartHost();
@@ -144,7 +144,7 @@ public void NetworkPrefabHandlerClass()
144144
public void Setup()
145145
{
146146
//Create, instantiate, and host
147-
NetworkManagerHelper.StartNetworkManager(out _,NetworkManagerHelper.NetworkManagerOperatingMode.None);
147+
NetworkManagerHelper.StartNetworkManager(out _, NetworkManagerHelper.NetworkManagerOperatingMode.None);
148148
}
149149

150150
[TearDown]
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
MIT License
22

3-
Copyright (c) 2018, 2019 Albin Corén
3+
Copyright (c) 2021 Unity Technologies
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
116

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)