(Case 1104590) PackedMemorySnapshot: "subSystemList" detected with wrong type

Using the UnityEditor.MemoryProfiler API to capture a PackedMemorySnapshot, causes some fields to be detected with the wrong type.

The following “PlayerLoopSystem” struct contains the “PlayerLoopSystem[ ] subSystemList” field in code.
When capturing a memory snapshot, this field is detected as ValueType, rather than an array.

This issue seems to occur with ScriptingBackend .NET 4 only. If ScriptingBackend is set to .NET 3.x, it causes a different issue, which I reported as Case 1104581 .

public struct PlayerLoopSystem // Located in namespace UnityEngine.Experimental.LowLevel
{
    public Type type;
    public PlayerLoopSystem[] subSystemList;  // this field is NOT detected as array in the memory snapshot
    public UpdateFunction updateDelegate;
    public IntPtr updateFunction;
    public IntPtr loopConditionFunction;
}

Reproduce

  • Open user attached project
  • Click Mainmenu > BugReport > Open TestCode Window
  • Click “Capture Memory” button

Observe the text shows “PlayerLoopSystem subSystemList; // (isArray=False, isValueType=True)”.

Actual
The “subSystemList” field is detected as ValueType.

Expected
The “subSystemList” field is detected as Array, which is a ReferenceType.

Sidenode
Why is this an issue you might think. The current information in the snapshot makes the “PlayerLoopSystem” struct look like it contains a field of a “PlayerLoopSystem” struct, thus infinite nesting. This infinite nesting causes the managed heap crawler in Heap Explorer to fail.

2 Likes

QA was able to reproduce the issue. Thank you!