Skip to content

chore(backport): 1.0.0 fix ilpp try catch il2cpp #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1308,26 +1308,29 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
processor.Emit(OpCodes.Ldc_I4, (int)NetworkBehaviour.__RpcExecStage.None);
processor.Emit(OpCodes.Stfld, m_NetworkBehaviour_rpc_exec_stage_FieldRef);

//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_0);
processor.Append(catchStarts);

// 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 equivelent to an interpolated string)
// 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_0);
processor.Emit(OpCodes.Ldloc, exceptionVariableIndex);
processor.Emit(OpCodes.Callvirt, exp);
processor.Emit(OpCodes.Call, stringFormat);

Expand Down