Skip to content

Mirror.NetworkInformationPreview was not disposed properly #4040

@Sphax84

Description

@Sphax84

Describe the bug
Unity6.1 is sometimes logging Warning and Error in Console. Most of the time it happens when a NetworkObject has been selected in project or scene view. It might happen only when the Preview window is independant/separated (not docked in the Inspector).

Mirror.NetworkInformationPreview was not disposed properly. Make sure that base.Cleanup is called if overriding the Cleanup method. If you are implementing this in an Editor or EditorWindow, don't forget to call ObjectPreview.Cleanup in OnDisable.
UnityEditor.ObjectPreview:Finalize ()

followed by Unity Error:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorStyles.get_label () (at <470d5ee51c814705aed43c16dbcfc099>:0)
Mirror.NetworkInformationPreview+Styles..ctor () (at Assets/Mirror/Editor/NetworkInformationPreview.cs:25)
Mirror.NetworkInformationPreview..ctor () (at Assets/Mirror/Editor/NetworkInformationPreview.cs:63)
System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
System.Activator.CreateInstance (System.Type type) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)
UnityEditor.PropertyEditor.GetPreviewsForType (UnityEditor.Editor editor) (at <470d5ee51c814705aed43c16dbcfc099>:0)
UnityEditor.PropertyEditor.CreatePreviewables () (at <470d5ee51c814705aed43c16dbcfc099>:0)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at <470d5ee51c814705aed43c16dbcfc099>:0)
UnityEditor.InspectorWindow.RedrawFromNative () (at <470d5ee51c814705aed43c16dbcfc099>:0)

[IMPORTANT] How can we reproduce the issue, step by step:

I think this warning and error is due to the Preview window not being docked. The dispose/cleanup is not done properly in that Preview editor class. Simply disabling that custom Editor Preview makes the warning&error stop (the workaround I use currently).

Expected behavior

The Custom Editor class for the preview of Network objects should be disposed and cleaned up properly as Unity suggest in its warning.

Desktop (please complete the following information):

  • OS: Windows11
  • Build target: Edit-time
  • Unity version: Unity6.1
  • Mirror branch: 96.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions