浏览代码

Fix null reference error when passing a null array to an action segment. (#4358)

/MLA-1734-demo-provider
GitHub 4 年前
当前提交
19a80b1c
共有 2 个文件被更改,包括 12 次插入3 次删除
  1. 7
      com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs
  2. 8
      com.unity.ml-agents/Tests/Editor/Actuators/ActionSegmentTests.cs

7
com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs


/// be set to 0 and the <see cref="Length"/> will be set to `actionArray.Length`.
/// </summary>
/// <param name="actionArray">The action array to use for the this segment.</param>
public ActionSegment(T[] actionArray) : this(actionArray, 0, actionArray.Length) { }
public ActionSegment(T[] actionArray)
: this(actionArray ?? System.Array.Empty<T>(), 0, actionArray?.Length ?? 0) { }
/// <summary>
/// Construct an <see cref="ActionSegment{T}"/> with an underlying array

public ActionSegment(T[] actionArray, int offset, int length)
{
#if DEBUG
CheckParameters(actionArray, offset, length);
CheckParameters(actionArray ?? System.Array.Empty<T>(), offset, length);
Array = actionArray;
Array = actionArray ?? System.Array.Empty<T>();
Offset = offset;
Length = length;
}

8
com.unity.ml-agents/Tests/Editor/Actuators/ActionSegmentTests.cs


}
}
[Test]
public void TestNullConstructor()
{
var actionSegment = new ActionSegment<float>(null);
Assert.IsTrue(actionSegment.Length == 0);
Assert.IsTrue(actionSegment.Array == Array.Empty<float>());
}
}
}
正在加载...
取消
保存