Skip to content

Commit 8a503a8

Browse files
authored
fix: if-guard NetworkManager.__rpc_name_table access (#1056)
1 parent 5deae10 commit 8a503a8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ internal void __endSendServerRpc(NetworkSerializer serializer, uint rpcMethodId,
9999
? NetworkManager.MessageQueueContainer.EndAddQueueItemToFrame(serializer.Writer, MessageQueueHistoryFrame.QueueFrameType.Inbound, serverRpcParams.Send.UpdateStage)
100100
: NetworkManager.MessageQueueContainer.EndAddQueueItemToFrame(serializer.Writer, MessageQueueHistoryFrame.QueueFrameType.Outbound, NetworkUpdateStage.PostLateUpdate);
101101

102+
#if DEVELOPMENT_BUILD || UNITY_EDITOR
102103
if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName))
103104
{
104105
NetworkManager.NetworkMetrics.TrackRpcSent(NetworkManager.ServerClientId, NetworkObjectId, rpcMethodName, rpcMessageSize);
105106
}
107+
#endif
106108
}
107109

108110
#pragma warning disable IDE1006 // disable naming rule violation check
@@ -207,10 +209,12 @@ internal void __endSendClientRpc(NetworkSerializer serializer, uint rpcMethodId,
207209

208210
var messageSize = NetworkManager.MessageQueueContainer.EndAddQueueItemToFrame(serializer.Writer, MessageQueueHistoryFrame.QueueFrameType.Outbound, NetworkUpdateStage.PostLateUpdate);
209211

212+
#if DEVELOPMENT_BUILD || UNITY_EDITOR
210213
if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName))
211214
{
212215
NetworkManager.NetworkMetrics.TrackRpcSent(NetworkManager.ConnectedClients.Select(x => x.Key).ToArray(), NetworkObjectId, rpcMethodName, messageSize);
213216
}
217+
#endif
214218
}
215219

216220
/// <summary>

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem, IProfilableTr
1919
// RuntimeAccessModifiersILPP will make this `public`
2020
internal static readonly Dictionary<uint, Action<NetworkBehaviour, NetworkSerializer, __RpcParams>> __rpc_func_table = new Dictionary<uint, Action<NetworkBehaviour, NetworkSerializer, __RpcParams>>();
2121

22-
#if UNITY_EDITOR || DEVELOPMENT_BUILD
23-
22+
#if DEVELOPMENT_BUILD || UNITY_EDITOR
2423
// RuntimeAccessModifiersILPP will make this `public`
2524
internal static readonly Dictionary<uint, string> __rpc_name_table = new Dictionary<uint, string>();
26-
#else // !(UNITY_EDITOR || DEVELOPMENT_BUILD)
27-
// RuntimeAccessModifiersILPP will make this `public`
28-
internal static readonly Dictionary<uint, string> __rpc_name_table = null; // not needed on release builds
29-
#endif // UNITY_EDITOR || DEVELOPMENT_BUILD
25+
#endif
26+
3027
#pragma warning restore IDE1006 // restore naming rule violation check
3128

3229
#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -35,7 +32,6 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem, IProfilableTr
3532
private static ProfilerMarker s_TransportConnect = new ProfilerMarker($"{nameof(NetworkManager)}.TransportConnect");
3633
private static ProfilerMarker s_HandleIncomingData = new ProfilerMarker($"{nameof(NetworkManager)}.{nameof(HandleIncomingData)}");
3734
private static ProfilerMarker s_TransportDisconnect = new ProfilerMarker($"{nameof(NetworkManager)}.TransportDisconnect");
38-
3935
private static ProfilerMarker s_InvokeRpc = new ProfilerMarker($"{nameof(NetworkManager)}.{nameof(InvokeRpc)}");
4036
#endif
4137

@@ -1263,10 +1259,12 @@ internal void InvokeRpc(MessageFrameItem item, NetworkUpdateStage networkUpdateS
12631259

12641260
__rpc_func_table[networkMethodId](networkBehaviour, new NetworkSerializer(item.NetworkReader), rpcParams);
12651261

1262+
#if DEVELOPMENT_BUILD || UNITY_EDITOR
12661263
if (__rpc_name_table.TryGetValue(networkMethodId, out var rpcMethodName))
12671264
{
12681265
NetworkMetrics.TrackRpcReceived(item.NetworkId, networkObjectId, rpcMethodName, item.StreamSize);
12691266
}
1267+
#endif
12701268
}
12711269
}
12721270
}

0 commit comments

Comments
 (0)