@@ -1308,26 +1308,29 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
1308
1308
processor . Emit ( OpCodes . Ldc_I4 , ( int ) NetworkBehaviour . __RpcExecStage . None ) ;
1309
1309
processor . Emit ( OpCodes . Stfld , m_NetworkBehaviour_rpc_exec_stage_FieldRef ) ;
1310
1310
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
-
1319
1311
// pull in the Exception Module
1320
1312
var exception = m_MainModule . ImportReference ( typeof ( Exception ) ) ;
1321
1313
1322
1314
// Get Exception.ToString()
1323
1315
var exp = m_MainModule . ImportReference ( typeof ( Exception ) . GetMethod ( "ToString" , new Type [ ] { } ) ) ;
1324
1316
1325
- // Get String.Format (This is equivelent to an interpolated string)
1317
+ // Get String.Format (This is equivalent to an interpolated string)
1326
1318
var stringFormat = m_MainModule . ImportReference ( typeof ( string ) . GetMethod ( "Format" , new Type [ ] { typeof ( string ) , typeof ( object ) } ) ) ;
1327
1319
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
+
1328
1331
// Load string for the error log that will be shown
1329
1332
processor . Emit ( OpCodes . Ldstr , $ "Unhandled RPC Exception:\n {{0}}") ;
1330
- processor . Emit ( OpCodes . Ldloc_0 ) ;
1333
+ processor . Emit ( OpCodes . Ldloc , exceptionVariableIndex ) ;
1331
1334
processor . Emit ( OpCodes . Callvirt , exp ) ;
1332
1335
processor . Emit ( OpCodes . Call , stringFormat ) ;
1333
1336
0 commit comments