Skip to content

Commit e28eb2a

Browse files
authored
fix: Adding FastBuffer extension methods for multiple instantiations of a generic type causes runtime errors [MTT-3063] (#2142)
Fixed RPC codegen failing to choose the correct extension methods for FastBufferReader and FastBufferWriter when the parameters were a generic type (i.e., List<int>) and extensions for multiple instantiations of that type have been defined (i.e., List<int> and List<string>)
1 parent ce1ab3c commit e28eb2a

3 files changed

Lines changed: 295 additions & 20 deletions

File tree

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77

88
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
99

10+
## [Unreleased]
11+
12+
### Fixed
13+
14+
- Fixed RPC codegen failing to choose the correct extension methods for FastBufferReader and FastBufferWriter when the parameters were a generic type (i.e., List<int>) and extensions for multiple instantiations of that type have been defined (i.e., List<int> and List<string>) (#2142)
15+
1016
## [1.0.1] - 2022-08-23
1117

1218
### Changed

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ private bool GetWriteMethodForParameter(TypeReference paramType, out MethodRefer
669669
{
670670
if (parameters[1].IsIn)
671671
{
672-
if (parameters[1].ParameterType.Resolve() == paramType.MakeByReferenceType().Resolve() &&
672+
if (((ByReferenceType)parameters[1].ParameterType).ElementType.FullName == paramType.FullName &&
673673
((ByReferenceType)parameters[1].ParameterType).ElementType.IsArray == paramType.IsArray)
674674
{
675675
methodRef = method;
@@ -679,8 +679,7 @@ private bool GetWriteMethodForParameter(TypeReference paramType, out MethodRefer
679679
}
680680
else
681681
{
682-
683-
if (parameters[1].ParameterType.Resolve() == paramType.Resolve() &&
682+
if (parameters[1].ParameterType.FullName == paramType.FullName &&
684683
parameters[1].ParameterType.IsArray == paramType.IsArray)
685684
{
686685
methodRef = method;
@@ -813,7 +812,7 @@ private bool GetReadMethodForParameter(TypeReference paramType, out MethodRefere
813812
var parameters = method.Resolve().Parameters;
814813
if (method.Name == k_ReadValueMethodName &&
815814
parameters[1].IsOut &&
816-
parameters[1].ParameterType.Resolve() == paramType.MakeByReferenceType().Resolve() &&
815+
((ByReferenceType)parameters[1].ParameterType).ElementType.FullName == paramType.FullName &&
817816
((ByReferenceType)parameters[1].ParameterType).ElementType.IsArray == paramType.IsArray)
818817
{
819818
methodRef = method;

0 commit comments

Comments
 (0)