@@ -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