Add a Try and Catch in the RPC invoking code #1071
Replies: 1 comment
|
Catching at the individual RPC dispatch boundary makes sense if each RPC is already length-framed. A user exception should fail that RPC, not abort processing of later RPCs in the same batch. The exception should be logged as an exception object, though. Converting it to text and rebuilding Unity links with a Windows-path regex will break on Unix paths, generated code, and several valid stack-trace formats. Unity already makes if (_serverRpcDelegates.TryGetValueIL2CPP(
hash, out ServerRpcDelegate data))
{
try
{
data.Invoke(reader, channel, sendingClient);
}
catch (Exception exception)
{
Debug.LogException(exception, gameObject);
}
}
else
{
_networkObjectCache.NetworkManager.LogError(
$"ServerRpc not found for hash {hash} on object " +
$"{gameObject.name} [id {ObjectId}].");
}The same policy should be applied consistently to ServerRpc, ObserversRpc, TargetRpc, and ReconcileRpc dispatch, ideally through one helper. The catch should surround the generated delegate invocation only, not the whole packet parser. One caveat is deserialization: continuing is safe only when the outer reader knows the RPC payload length and advances to the next frame even if the generated delegate throws before consuming all arguments. That invariant deserves a regression test alongside the change. The current unguarded invocation is here: NetworkBehaviour.RPCs.cs. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When a RPC encounters a error, it makes all RPCs that were to come after it not run.
The solution to this is to add a try-catch block where all RPCs get invoked: NetworkBehaviour.RPCs.cs. This could be an option on the network manager.
The Regex below is to fix the issue with printing Exceptions, where they will not have the correct blue links that take you to the line in your code.
All reactions