Skip to content

Commit 35e14e8

Browse files
fix: Resolving issue where IL2CPP would not compile (#1359)
* fix: Fixing an issue where IL2CPP is not smart enough to ensure what is being popped off the stack so we need to be explicit with a variable * fix: standards.py * [skip ci] updating changelog
1 parent 9d6034e commit 35e14e8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2222

2323
- Overflow exception when syncing Animator state. (#1327)
2424
- Added `try`/`catch` around RPC calls, preventing exception from causing further RPC calls to fail (#1329)
25+
- IL2CPP would not properly compile (#1359)
2526

2627
## [1.0.0-pre.2] - 2021-10-19
2728

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)