Skip to content

Commit

Permalink
fix: Adding FastBuffer extension methods for multiple instantiations …
Browse files Browse the repository at this point in the history
…of a generic type causes runtime errors [MTT-3063] (Unity-Technologies#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>)
  • Loading branch information
ShadauxCat authored Aug 23, 2022
1 parent ce1ab3c commit e28eb2a
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 20 deletions.
6 changes: 6 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

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

## [Unreleased]

### Fixed

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

## [1.0.1] - 2022-08-23

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ private bool GetWriteMethodForParameter(TypeReference paramType, out MethodRefer
{
if (parameters[1].IsIn)
{
if (parameters[1].ParameterType.Resolve() == paramType.MakeByReferenceType().Resolve() &&
if (((ByReferenceType)parameters[1].ParameterType).ElementType.FullName == paramType.FullName &&
((ByReferenceType)parameters[1].ParameterType).ElementType.IsArray == paramType.IsArray)
{
methodRef = method;
Expand All @@ -679,8 +679,7 @@ private bool GetWriteMethodForParameter(TypeReference paramType, out MethodRefer
}
else
{

if (parameters[1].ParameterType.Resolve() == paramType.Resolve() &&
if (parameters[1].ParameterType.FullName == paramType.FullName &&
parameters[1].ParameterType.IsArray == paramType.IsArray)
{
methodRef = method;
Expand Down Expand Up @@ -813,7 +812,7 @@ private bool GetReadMethodForParameter(TypeReference paramType, out MethodRefere
var parameters = method.Resolve().Parameters;
if (method.Name == k_ReadValueMethodName &&
parameters[1].IsOut &&
parameters[1].ParameterType.Resolve() == paramType.MakeByReferenceType().Resolve() &&
((ByReferenceType)parameters[1].ParameterType).ElementType.FullName == paramType.FullName &&
((ByReferenceType)parameters[1].ParameterType).ElementType.IsArray == paramType.IsArray)
{
methodRef = method;
Expand Down
Loading

0 comments on commit e28eb2a

Please sign in to comment.