Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compile error with generic NetworkBehaviour singletons #2603

Merged
merged 4 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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 an ILPP compile error when creating a generic NetworkBehaviour singleton with a static T instance. (#2603)

## [1.5.1] - 2023-06-07

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static uint Hash(this MethodDefinition methodDefinition)

public static bool IsSubclassOf(this TypeDefinition typeDefinition, string classTypeFullName)
{
if (!typeDefinition.IsClass)
if (typeDefinition == null || !typeDefinition.IsClass)
{
return false;
}
Expand Down Expand Up @@ -154,6 +154,10 @@ public static MethodReference MakeGeneric(this MethodReference self, params Type

public static bool IsSubclassOf(this TypeReference typeReference, TypeReference baseClass)
{
if (typeReference == null)
{
return false;
}
var type = typeReference.Resolve();
if (type?.BaseType == null || type.BaseType.Name == nameof(Object))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,12 @@ private void GenerateVariableInitialization(TypeDefinition type)
}
field = new FieldReference(fieldDefinition.Name, fieldDefinition.FieldType, genericType);
}

if (field.FieldType.Resolve() == null)
{
continue;
}

if (!field.FieldType.IsArray && !field.FieldType.Resolve().IsArray && field.FieldType.IsSubclassOf(m_NetworkVariableBase_TypeRef))
{
// if({variable} == null) {
Expand Down