diff --git a/com.unity.render-pipelines.core/Runtime/Common/DynamicArray.cs b/com.unity.render-pipelines.core/Runtime/Common/DynamicArray.cs
index 2e61659d3b0..f27a883a9be 100644
--- a/com.unity.render-pipelines.core/Runtime/Common/DynamicArray.cs
+++ b/com.unity.render-pipelines.core/Runtime/Common/DynamicArray.cs
@@ -87,7 +87,7 @@ public int Add(in T value)
/// The array whose elements should be added to the end of the DynamicArray. The array itself cannot be null, but it can contain elements that are null, if type T is a reference type.
public void AddRange(DynamicArray array)
{
- Reserve(size + array.size);
+ Reserve(size + array.size, true);
for (int i = 0; i < array.size; ++i)
m_Array[size++] = array[i];
}
diff --git a/com.unity.render-pipelines.core/Tests/Editor/DynamicArrayTests.cs b/com.unity.render-pipelines.core/Tests/Editor/DynamicArrayTests.cs
index 8926775936d..1f6c78dcd74 100644
--- a/com.unity.render-pipelines.core/Tests/Editor/DynamicArrayTests.cs
+++ b/com.unity.render-pipelines.core/Tests/Editor/DynamicArrayTests.cs
@@ -58,6 +58,26 @@ public void TestAddRangeCorrectElements()
Assert.AreEqual(4, m_DynamicArray.size);
}
+ [Test]
+ public void TestAddRangeOutOfSpaceKeepPreviousElements()
+ {
+ var smallDynamicArray = new DynamicArray(2);
+ smallDynamicArray[0] = 1;
+ smallDynamicArray[1] = 2;
+
+ var otherArray = new DynamicArray();
+ otherArray.Add(3);
+ otherArray.Add(4);
+
+ smallDynamicArray.AddRange(otherArray);
+
+ Assert.AreEqual(1, smallDynamicArray[0]);
+ Assert.AreEqual(2, smallDynamicArray[1]);
+ Assert.AreEqual(3, smallDynamicArray[2]);
+ Assert.AreEqual(4, smallDynamicArray[3]);
+ Assert.AreEqual(4, smallDynamicArray.size);
+ }
+
[Test]
public void TestRemoveElementCorrectSize()
{