Skip to content

Commit 790de71

Browse files
fix: resolving issue with IL2CPP compiling (#1375)
Co-authored-by: Matt Walsh <69258106+mattwalsh-unity@users.noreply.github.com>
1 parent e30e9ff commit 790de71

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,26 +1308,29 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
13081308
processor.Emit(OpCodes.Ldc_I4, (int)NetworkBehaviour.__RpcExecStage.None);
13091309
processor.Emit(OpCodes.Stfld, m_NetworkBehaviour_rpc_exec_stage_FieldRef);
13101310

1311-
//try ends/catch begins
1312-
var catchEnds = processor.Create(OpCodes.Nop);
1313-
processor.Emit(OpCodes.Leave, catchEnds);
1314-
1315-
// Load the Exception onto the stack
1316-
var catchStarts = processor.Create(OpCodes.Stloc_0);
1317-
processor.Append(catchStarts);
1318-
13191311
// pull in the Exception Module
13201312
var exception = m_MainModule.ImportReference(typeof(Exception));
13211313

13221314
// Get Exception.ToString()
13231315
var exp = m_MainModule.ImportReference(typeof(Exception).GetMethod("ToString", new Type[] { }));
13241316

1325-
// Get String.Format (This is equivelent to an interpolated string)
1317+
// Get String.Format (This is equivalent to an interpolated string)
13261318
var stringFormat = m_MainModule.ImportReference(typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) }));
13271319

1320+
nhandler.Body.Variables.Add(new VariableDefinition(exception));
1321+
int exceptionVariableIndex = nhandler.Body.Variables.Count - 1;
1322+
1323+
//try ends/catch begins
1324+
var catchEnds = processor.Create(OpCodes.Nop);
1325+
processor.Emit(OpCodes.Leave, catchEnds);
1326+
1327+
// Load the Exception onto the stack
1328+
var catchStarts = processor.Create(OpCodes.Stloc, exceptionVariableIndex);
1329+
processor.Append(catchStarts);
1330+
13281331
// Load string for the error log that will be shown
13291332
processor.Emit(OpCodes.Ldstr, $"Unhandled RPC Exception:\n {{0}}");
1330-
processor.Emit(OpCodes.Ldloc_0);
1333+
processor.Emit(OpCodes.Ldloc, exceptionVariableIndex);
13311334
processor.Emit(OpCodes.Callvirt, exp);
13321335
processor.Emit(OpCodes.Call, stringFormat);
13331336

0 commit comments

Comments
 (0)