Skip to content

Commit bb7998e

Browse files
ShadauxCatNoelStephensUnity0xFA11
authored andcommitted
fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. [MTT-1378] (Unity-Technologies#1739)
* fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. * Standards and changelog. * Standards fixes * It would be good to check in the right file. * I swear these tests passed before but I have no idea how. Also review feedback. * Address review feedback. * Switched to LogAssert.Expect * Updated tests to NetcodeIntegrationTest style * Standards fix * Rewrote tests according to feedback. Also fixed merge issue with changelog. * Test the behavior on both server and client * style fixing white space issue. * Update com.unity.netcode.gameobjects/CHANGELOG.md Co-authored-by: Fatih Mar <mfatihmar@gmail.com> Co-authored-by: Noel Stephens <noel.stephens@unity3d.com> Co-authored-by: Fatih Mar <mfatihmar@gmail.com>
1 parent 93e0680 commit bb7998e

5 files changed

Lines changed: 344 additions & 17 deletions

File tree

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1212
### Fixed
1313

1414
- Fixed RPC codegen failing to choose the correct extension methods for FastBufferReader and FastBufferWriter when the parameters were a generic type (i.e., List<int>) and extensions for multiple instantiations of that type have been defined (i.e., List<int> and List<string>) (#2142)
15+
- Fixed throwing an exception in OnNetworkUpdate causing other OnNetworkUpdate calls to not be executed. (#1739)
1516

1617
## [1.0.1] - 2022-08-23
1718

@@ -20,7 +21,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2021
- Changed version to 1.0.1. (#2131)
2122
- Updated dependency on `com.unity.transport` to 1.2.0. (#2129)
2223
- When using `UnityTransport`, _reliable_ payloads are now allowed to exceed the configured 'Max Payload Size'. Unreliable payloads remain bounded by this setting. (#2081)
23-
- Preformance improvements for cases with large number of NetworkObjects, by not iterating over all unchanged NetworkObjects
24+
- Performance improvements for cases with large number of NetworkObjects, by not iterating over all unchanged NetworkObjects
2425

2526
### Fixed
2627

@@ -238,7 +239,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
238239

239240
- ResetTrigger function to NetworkAnimator (#1327)
240241

241-
### Fixed
242+
### Fixed
242243

243244
- Overflow exception when syncing Animator state. (#1327)
244245
- Added `try`/`catch` around RPC calls, preventing exception from causing further RPC calls to fail (#1329)
@@ -263,7 +264,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
263264
- Added `ClientNetworkTransform` sample to the SDK package (#1168)
264265
- Added `Bootstrap` sample to the SDK package (#1140)
265266
- Enhanced `NetworkSceneManager` implementation with additive scene loading capabilities (#1080, #955, #913)
266-
- `NetworkSceneManager.OnSceneEvent` provides improved scene event notificaitons
267+
- `NetworkSceneManager.OnSceneEvent` provides improved scene event notificaitons
267268
- Enhanced `NetworkTransform` implementation with per axis/component based and threshold based state replication (#1042, #1055, #1061, #1084, #1101)
268269
- Added a jitter-resistent `BufferedLinearInterpolator<T>` for `NetworkTransform` (#1060)
269270
- Implemented `NetworkPrefabHandler` that provides support for object pooling and `NetworkPrefab` overrides (#1073, #1004, #977, #905,#749, #727)
@@ -320,7 +321,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
320321
- Removed `NetworkDictionary`, `NetworkSet` (#1149)
321322
- Removed `NetworkVariableSettings` (#1097)
322323
- Removed predefined `NetworkVariable<T>` types (#1093)
323-
- Removed `NetworkVariableBool`, `NetworkVariableByte`, `NetworkVariableSByte`, `NetworkVariableUShort`, `NetworkVariableShort`, `NetworkVariableUInt`, `NetworkVariableInt`, `NetworkVariableULong`, `NetworkVariableLong`, `NetworkVariableFloat`, `NetworkVariableDouble`, `NetworkVariableVector2`, `NetworkVariableVector3`, `NetworkVariableVector4`, `NetworkVariableColor`, `NetworkVariableColor32`, `NetworkVariableRay`, `NetworkVariableQuaternion`
324+
- Removed `NetworkVariableBool`, `NetworkVariableByte`, `NetworkVariableSByte`, `NetworkVariableUShort`, `NetworkVariableShort`, `NetworkVariableUInt`, `NetworkVariableInt`, `NetworkVariableULong`, `NetworkVariableLong`, `NetworkVariableFloat`, `NetworkVariableDouble`, `NetworkVariableVector2`, `NetworkVariableVector3`, `NetworkVariableVector4`, `NetworkVariableColor`, `NetworkVariableColor32`, `NetworkVariableRay`, `NetworkVariableQuaternion`
324325
- Removed `NetworkChannel` and `MultiplexTransportAdapter` (#1133)
325326
- Removed ILPP backend for 2019.4, minimum required version is 2020.3+ (#895)
326327
- `NetworkManager.NetworkConfig` had the following properties removed: (#1080)
@@ -392,14 +393,14 @@ This is the initial experimental Unity MLAPI Package, v0.1.0.
392393
- Integrated MLAPI with the Unity Profiler for versions 2020.2 and later:
393394
- Added new profiler modules for MLAPI that report important network data.
394395
- Attached the profiler to a remote player to view network data over the wire.
395-
- A test project is available for building and experimenting with MLAPI features. This project is available in the MLAPI GitHub [testproject folder](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/tree/release/0.1.0/testproject).
396+
- A test project is available for building and experimenting with MLAPI features. This project is available in the MLAPI GitHub [testproject folder](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/tree/release/0.1.0/testproject).
396397
- Added a [MLAPI Community Contributions](https://github.com/Unity-Technologies/mlapi-community-contributions/tree/master/com.mlapi.contrib.extensions) new GitHub repository to accept extensions from the MLAPI community. Current extensions include moved MLAPI features for lag compensation (useful for Server Authoritative actions) and `TrackedObject`.
397398

398399
### Changed
399400

400401
- [GitHub 520](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/520): MLAPI now uses the Unity Package Manager for installation management.
401-
- Added functionality and usability to `NetworkVariable`, previously called `NetworkVar`. Updates enhance options and fully replace the need for `SyncedVar`s.
402-
- [GitHub 507](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/507): Reimplemented `NetworkAnimator`, which synchronizes animation states for networked objects.
402+
- Added functionality and usability to `NetworkVariable`, previously called `NetworkVar`. Updates enhance options and fully replace the need for `SyncedVar`s.
403+
- [GitHub 507](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/507): Reimplemented `NetworkAnimator`, which synchronizes animation states for networked objects.
403404
- GitHub [444](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/444) and [455](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/455): Channels are now represented as bytes instead of strings.
404405

405406
For users of previous versions of MLAPI, this release renames APIs due to refactoring. All obsolete marked APIs have been removed as per [GitHub 513](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/513) and [GitHub 514](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/514).
@@ -432,7 +433,7 @@ For users of previous versions of MLAPI, this release renames APIs due to refact
432433

433434
### Fixed
434435

435-
- [GitHub 460](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/460): Fixed an issue for RPC where the host-server was not receiving RPCs from the host-client and vice versa without the loopback flag set in `NetworkingManager`.
436+
- [GitHub 460](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/460): Fixed an issue for RPC where the host-server was not receiving RPCs from the host-client and vice versa without the loopback flag set in `NetworkingManager`.
436437
- Fixed an issue where data in the Profiler was incorrectly aggregated and drawn, which caused the profiler data to increment indefinitely instead of resetting each frame.
437438
- Fixed an issue the client soft-synced causing PlayMode client-only scene transition issues, caused when running the client in the editor and the host as a release build. Users may have encountered a soft sync of `NetworkedInstanceId` issues in the `SpawnManager.ClientCollectSoftSyncSceneObjectSweep` method.
438439
- [GitHub 458](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/458): Fixed serialization issues in `NetworkList` and `NetworkDictionary` when running in Server mode.
@@ -447,10 +448,10 @@ With a new release of MLAPI in Unity, some features have been removed:
447448
- SyncVars have been removed from MLAPI. Use `NetworkVariable`s in place of this functionality. <!-- MTT54 -->
448449
- [GitHub 527](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/527): Lag compensation systems and `TrackedObject` have moved to the new [MLAPI Community Contributions](https://github.com/Unity-Technologies/mlapi-community-contributions/tree/master/com.mlapi.contrib.extensions) repo.
449450
- [GitHub 509](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/509): Encryption has been removed from MLAPI. The `Encryption` option in `NetworkConfig` on the `NetworkingManager` is not available in this release. This change will not block game creation or running. A current replacement for this functionality is not available, and may be developed in future releases. See the following changes:
450-
- Removed `SecuritySendFlags` from all APIs.
451-
- Removed encryption, cryptography, and certificate configurations from APIs including `NetworkManager` and `NetworkConfig`.
452-
- Removed "hail handshake", including `NetworkManager` implementation and `NetworkConstants` entries.
453-
- Modified `RpcQueue` and `RpcBatcher` internals to remove encryption and authentication from reading and writing.
451+
- Removed `SecuritySendFlags` from all APIs.
452+
- Removed encryption, cryptography, and certificate configurations from APIs including `NetworkManager` and `NetworkConfig`.
453+
- Removed "hail handshake", including `NetworkManager` implementation and `NetworkConstants` entries.
454+
- Modified `RpcQueue` and `RpcBatcher` internals to remove encryption and authentication from reading and writing.
454455
- Removed the previous MLAPI Profiler editor window from Unity versions 2020.2 and later.
455456
- Removed previous MLAPI Convenience and Performance RPC APIs with the new standard RPC API. See [RFC #1](https://github.com/Unity-Technologies/com.unity.multiplayer.rfcs/blob/master/text/0001-std-rpc-api.md) for details.
456457
- [GitHub 520](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/pull/520): Removed the MLAPI Installer.
@@ -463,7 +464,7 @@ With a new release of MLAPI in Unity, some features have been removed:
463464
- For `NetworkVariable`, the `NetworkDictionary` `List` and `Set` must use the `reliableSequenced` channel.
464465
- `NetworkObjects`s are supported but when spawning a prefab with nested child network objects you have to manually call spawn on them
465466
- `NetworkTransform` have the following issues:
466-
- Replicated objects may have jitter.
467+
- Replicated objects may have jitter.
467468
- The owner is always authoritative about the object's position.
468469
- Scale is not synchronized.
469470
- Connection Approval is not called on the host client.

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,28 @@ internal void InternalOnNetworkSpawn()
440440

441441
internal void VisibleOnNetworkSpawn()
442442
{
443-
OnNetworkSpawn();
443+
try
444+
{
445+
OnNetworkSpawn();
446+
}
447+
catch (Exception e)
448+
{
449+
Debug.LogException(e);
450+
}
444451
}
445452

446453
internal void InternalOnNetworkDespawn()
447454
{
448455
IsSpawned = false;
449456
UpdateNetworkProperties();
450-
OnNetworkDespawn();
457+
try
458+
{
459+
OnNetworkDespawn();
460+
}
461+
catch (Exception e)
462+
{
463+
Debug.LogException(e);
464+
}
451465
}
452466

453467
/// <summary>

com.unity.netcode.gameobjects/TestHelpers/Runtime/MessageHooks.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ namespace Unity.Netcode.TestHelpers.Runtime
44
{
55
internal class MessageHooks : INetworkHooks
66
{
7-
public bool IsWaiting;
7+
public bool IsWaiting = true;
88
public delegate bool MessageReceiptCheck(object receivedMessage);
99
public MessageReceiptCheck ReceiptCheck;
1010

11+
public static bool CurrentMessageHasTriggerdAHook = false;
12+
1113
public static bool CheckForMessageOfType<T>(object receivedMessage) where T : INetworkMessage
1214
{
1315
return receivedMessage is T;
@@ -57,13 +59,23 @@ public bool OnVerifyCanReceive(ulong senderId, Type messageType, FastBufferReade
5759

5860
public void OnBeforeHandleMessage<T>(ref T message, ref NetworkContext context) where T : INetworkMessage
5961
{
62+
// The way the system works, it goes through all hooks and calls OnBeforeHandleMessage, then handles the message,
63+
// then goes thorugh all hooks and calls OnAfterHandleMessage.
64+
// This ensures each message only manages to activate a single message hook - because we know that only
65+
// one message will ever be handled between OnBeforeHandleMessage and OnAfterHandleMessage,
66+
// we can reset the flag here, and then in OnAfterHandleMessage, the moment the message matches a hook,
67+
// it'll flip this flag back on, and then other hooks will stop checking that message.
68+
// Without this flag, waiting for 10 messages of the same type isn't possible - all 10 hooks would get
69+
// tripped by the first message.
70+
CurrentMessageHasTriggerdAHook = false;
6071
}
6172

6273
public void OnAfterHandleMessage<T>(ref T message, ref NetworkContext context) where T : INetworkMessage
6374
{
64-
if (IsWaiting && (ReceiptCheck == null || ReceiptCheck.Invoke(message)))
75+
if (!CurrentMessageHasTriggerdAHook && IsWaiting && (ReceiptCheck == null || ReceiptCheck.Invoke(message)))
6576
{
6677
IsWaiting = false;
78+
CurrentMessageHasTriggerdAHook = true;
6779
}
6880
}
6981
}

0 commit comments

Comments
 (0)