com.unity.netcode.gameobjects@1.0.0-pre.3
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.0.0-pre.3] - 2021-10-22 ### Added - ResetTrigger function to NetworkAnimator (#1327) ### Fixed - Overflow exception when syncing Animator state. (#1327) - Added `try`/`catch` around RPC calls, preventing exception from causing further RPC calls to fail (#1329) - Fixed an issue where ServerClientId and LocalClientId could have the same value, causing potential confusion, and also fixed an issue with the UNet where the server could be identified with two different values, one of which might be the same as LocalClientId, and the other of which would not.(#1368) - IL2CPP would not properly compile (#1359)
This commit is contained in:
@@ -1127,6 +1127,11 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
nhandler.Parameters.Add(new ParameterDefinition("rpcParams", ParameterAttributes.None, m_RpcParams_TypeRef));
|
||||
|
||||
var processor = nhandler.Body.GetILProcessor();
|
||||
|
||||
// begin Try/Catch
|
||||
var tryStart = processor.Create(OpCodes.Nop);
|
||||
processor.Append(tryStart);
|
||||
|
||||
var isServerRpc = rpcAttribute.AttributeType.FullName == CodeGenHelpers.ServerRpcAttribute_FullName;
|
||||
var requireOwnership = true; // default value MUST be = `ServerRpcAttribute.RequireOwnership`
|
||||
foreach (var attrField in rpcAttribute.Fields)
|
||||
@@ -1303,7 +1308,54 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
processor.Emit(OpCodes.Ldc_I4, (int)NetworkBehaviour.__RpcExecStage.None);
|
||||
processor.Emit(OpCodes.Stfld, m_NetworkBehaviour_rpc_exec_stage_FieldRef);
|
||||
|
||||
// pull in the Exception Module
|
||||
var exception = m_MainModule.ImportReference(typeof(Exception));
|
||||
|
||||
// Get Exception.ToString()
|
||||
var exp = m_MainModule.ImportReference(typeof(Exception).GetMethod("ToString", new Type[] { }));
|
||||
|
||||
// Get String.Format (This is equivalent to an interpolated string)
|
||||
var stringFormat = m_MainModule.ImportReference(typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) }));
|
||||
|
||||
nhandler.Body.Variables.Add(new VariableDefinition(exception));
|
||||
int exceptionVariableIndex = nhandler.Body.Variables.Count - 1;
|
||||
|
||||
//try ends/catch begins
|
||||
var catchEnds = processor.Create(OpCodes.Nop);
|
||||
processor.Emit(OpCodes.Leave, catchEnds);
|
||||
|
||||
// Load the Exception onto the stack
|
||||
var catchStarts = processor.Create(OpCodes.Stloc, exceptionVariableIndex);
|
||||
processor.Append(catchStarts);
|
||||
|
||||
// Load string for the error log that will be shown
|
||||
processor.Emit(OpCodes.Ldstr, $"Unhandled RPC Exception:\n {{0}}");
|
||||
processor.Emit(OpCodes.Ldloc, exceptionVariableIndex);
|
||||
processor.Emit(OpCodes.Callvirt, exp);
|
||||
processor.Emit(OpCodes.Call, stringFormat);
|
||||
|
||||
// Call Debug.LogError
|
||||
processor.Emit(OpCodes.Call, m_Debug_LogError_MethodRef);
|
||||
|
||||
// reset NetworkBehaviour.__rpc_exec_stage = __RpcExecStage.None;
|
||||
processor.Emit(OpCodes.Ldarg_0);
|
||||
processor.Emit(OpCodes.Ldc_I4, (int)NetworkBehaviour.__RpcExecStage.None);
|
||||
processor.Emit(OpCodes.Stfld, m_NetworkBehaviour_rpc_exec_stage_FieldRef);
|
||||
|
||||
// catch ends
|
||||
processor.Append(catchEnds);
|
||||
|
||||
processor.Body.ExceptionHandlers.Add(new ExceptionHandler(ExceptionHandlerType.Catch)
|
||||
{
|
||||
CatchType = exception,
|
||||
TryStart = tryStart,
|
||||
TryEnd = catchStarts,
|
||||
HandlerStart = catchStarts,
|
||||
HandlerEnd = catchEnds
|
||||
});
|
||||
|
||||
processor.Emit(OpCodes.Ret);
|
||||
|
||||
return nhandler;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user