Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.4.0-pre.5] - 2024-02-13

### Changed

* Updated Burst dependency to version 1.8.12

### Fixed

* Memory leaks in unit tests.
* Memory leak when using `NativeBitArrayUnsafeUtility.ConvertExistingDataToNativeBitArray`.
* Brace parsing in FixedString AppendFormat handles incorrect formatting now

### Updated

* Upgraded Test Framework version to 1.4.3
  • Loading branch information
Unity Technologies committed Feb 13, 2024
1 parent b445b9b commit 6aad0ee
Show file tree
Hide file tree
Showing 21 changed files with 688 additions and 259 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# Changelog
## [2.4.0-pre.5] - 2024-02-13

### Changed

* Updated Burst dependency to version 1.8.12

### Fixed

* Memory leaks in unit tests.
* Memory leak when using `NativeBitArrayUnsafeUtility.ConvertExistingDataToNativeBitArray`.
* Brace parsing in FixedString AppendFormat handles incorrect formatting now

### Updated

* Upgraded Test Framework version to 1.4.3



## [2.4.0-pre.2] - 2023-11-28

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
com.unity.collections copyright © 2023 Unity Technologies
com.unity.collections copyright © 2024 Unity Technologies

Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
workers = args[0];
}

public void AllocNativeContainer(int capacity) => QueueParallelUtil.AllocInt(ref nativeContainer, 0, false);
public void AllocNativeContainer(int capacity) => QueueParallelUtil.AllocInt(ref nativeContainer, capacity >= 0 ? 0 : -1, false);
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity) => QueueParallelUtil.AllocBclContainer(0, false);

Expand Down
6 changes: 3 additions & 3 deletions Unity.Collections.PerformanceTests/QueuePerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ struct QueueEnqueueGrow : IBenchmarkContainer

void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;

public void AllocNativeContainer(int capacity) => QueueUtil.AllocInt(ref nativeContainer, 0, false);
public void AllocUnsafeContainer(int capacity) => QueueUtil.AllocInt(ref unsafeContainer, 0, false);
public object AllocBclContainer(int capacity) => QueueUtil.AllocBclContainer(0, false);
public void AllocNativeContainer(int capacity) => QueueUtil.AllocInt(ref nativeContainer, capacity >= 0 ? 0 : -1, false);
public void AllocUnsafeContainer(int capacity) => QueueUtil.AllocInt(ref unsafeContainer, capacity >= 0 ? 0 : -1, false);
public object AllocBclContainer(int capacity) => QueueUtil.AllocBclContainer(capacity >= 0 ? 0 : -1, false);

public void MeasureNativeContainer()
{
Expand Down
2 changes: 1 addition & 1 deletion Unity.Collections.Tests/AllocatorCustomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void CustomAllocatorHandle_MultiThreadWorks()

Task.WaitAll(taskList.ToArray());

exampleStruct.customAllocator.Dispose();
exampleStruct.Dispose();
}
}
#endregion // allocator-custom-user-struct
Expand Down
98 changes: 87 additions & 11 deletions Unity.Collections.Tests/FixedStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void FixedStringNFormatExtension1Params()
aa.Junk();
FixedStringN format = "{0}";
FixedString32Bytes arg0 = "a";
aa.AppendFormat(format, arg0);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
Assert.AreEqual("a", aa);
aa.AssertNullTerminated();
}
Expand All @@ -60,7 +60,7 @@ public void FixedStringNFormatExtension2Params()
FixedStringN format = "{0} {1}";
FixedString32Bytes arg0 = "a";
FixedString32Bytes arg1 = "b";
aa.AppendFormat(format, arg0, arg1);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1));
Assert.AreEqual("a b", aa);
aa.AssertNullTerminated();
}
Expand All @@ -75,7 +75,7 @@ public void FixedStringNFormatExtension3Params()
FixedString32Bytes arg0 = "a";
FixedString32Bytes arg1 = "b";
FixedString32Bytes arg2 = "c";
aa.AppendFormat(format, arg0, arg1, arg2);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2));
Assert.AreEqual("a b c", aa);
aa.AssertNullTerminated();
}
Expand All @@ -84,14 +84,14 @@ public void FixedStringNFormatExtension3Params()
[Test]
public void FixedStringNFormatExtension4Params()
{
FixedStringN aa = default;
FixedStringN aa = default;
aa.Junk();
FixedStringN format = "{0} {1} {2} {3}";
FixedString32Bytes arg0 = "a";
FixedString32Bytes arg1 = "b";
FixedString32Bytes arg2 = "c";
FixedString32Bytes arg3 = "d";
aa.AppendFormat(format, arg0, arg1, arg2, arg3);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3));
Assert.AreEqual("a b c d", aa);
aa.AssertNullTerminated();
}
Expand All @@ -108,7 +108,7 @@ public void FixedStringNFormatExtension5Params()
FixedString32Bytes arg2 = "c";
FixedString32Bytes arg3 = "d";
FixedString32Bytes arg4 = "e";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4));
Assert.AreEqual("a b c d e", aa);
aa.AssertNullTerminated();
}
Expand All @@ -126,7 +126,7 @@ public void FixedStringNFormatExtension6Params()
FixedString32Bytes arg3 = "d";
FixedString32Bytes arg4 = "e";
FixedString32Bytes arg5 = "f";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5));
Assert.AreEqual("a b c d e f", aa);
aa.AssertNullTerminated();
}
Expand All @@ -145,7 +145,7 @@ public void FixedStringNFormatExtension7Params()
FixedString32Bytes arg4 = "e";
FixedString32Bytes arg5 = "f";
FixedString32Bytes arg6 = "g";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6));
Assert.AreEqual("a b c d e f g", aa);
aa.AssertNullTerminated();
}
Expand All @@ -165,7 +165,7 @@ public void FixedStringNFormatExtension8Params()
FixedString32Bytes arg5 = "f";
FixedString32Bytes arg6 = "g";
FixedString32Bytes arg7 = "h";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7));
Assert.AreEqual("a b c d e f g h", aa);
aa.AssertNullTerminated();
}
Expand All @@ -186,7 +186,7 @@ public void FixedStringNFormatExtension9Params()
FixedString32Bytes arg6 = "g";
FixedString32Bytes arg7 = "h";
FixedString32Bytes arg8 = "i";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
Assert.AreEqual("a b c d e f g h i", aa);
aa.AssertNullTerminated();
}
Expand All @@ -208,11 +208,87 @@ public void FixedStringNFormatExtension10Params()
FixedString32Bytes arg7 = "h";
FixedString32Bytes arg8 = "i";
FixedString32Bytes arg9 = "j";
aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
Assert.AreEqual("a b c d e f g h i j", aa);
aa.AssertNullTerminated();
}

[Test]
public void FixedStringNFormatBadFormat()
{
FixedStringN aa = default;
aa.Junk();
FixedStringN format = "{10}";
FixedString32Bytes arg0 = "a";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0 } ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{ 0} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0a} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{012 ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0{ ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0{ ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0} } ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{ {0} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{{{0}} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{{0} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
format = "{0}} ";
Assert.AreEqual(FormatError.BadFormatSpecifier, aa.AppendFormat(format, arg0));
aa.AssertNullTerminated();
}

[Test]
public void FixedStringNFormatOverflow()
{
FixedString32Bytes aa = default;
aa.Junk();
FixedStringN format = "{0}";
FixedStringN arg0 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Assert.AreEqual(FormatError.Overflow, aa.AppendFormat(format, arg0));
}

[Test]
public void FixedStringNFormatBraces()
{
FixedStringN aa = default;
aa.Junk();
FixedStringN format = "{{0}}";
FixedString32Bytes arg0 = "42";
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
Assert.AreEqual("{0}", aa);
aa.AssertNullTerminated();

aa = default;
format = "{{{0}}}";
arg0 = "43";
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
Assert.AreEqual("{43}", aa);
aa.AssertNullTerminated();

aa = default;
format = "{{{0}";
arg0 = "44";
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
Assert.AreEqual("{44", aa);
aa.AssertNullTerminated();

aa = default;
format = "{0}}}";
arg0 = "45";
Assert.AreEqual(FormatError.None, aa.AppendFormat(format, arg0));
Assert.AreEqual("45}", aa);
aa.AssertNullTerminated();
}

[Test]
public void FixedStringNAppendString()
{
Expand Down
4 changes: 3 additions & 1 deletion Unity.Collections.Tests/GenericContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ void Test_Change_Length_Missing_Dependency<T, U>(T container)
[TestRequiresCollectionChecks()]
public void IIndexable_Change_Length_Missing_Dependency()
{
Test_Change_Length_Missing_Dependency<NativeList<int>, int>(new NativeList<int>(16, Allocator.Persistent));
var container = new NativeList<int>(16, Allocator.Persistent);
Test_Change_Length_Missing_Dependency<NativeList<int>, int>(container);
container.Dispose();
}
#endif
//-------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions Unity.Collections.Tests/NativeRingQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,7 @@ public void NativeRingQueue_UseInJob()

Assert.AreEqual(987, container.Dequeue());
Assert.AreEqual(0, container.Length);

container.Dispose();
}
}
6 changes: 6 additions & 0 deletions Unity.Collections.Tests/NativeTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ public void NativeTextReadOnlyCannotScheduledSourceTextForWrite()
});
handle.Complete();

a.Dispose();

Assert.IsTrue(allocator.WasUsed);
allocator.Dispose();
Expand Down Expand Up @@ -875,6 +876,8 @@ public void NativeTextReadOnlyCanReadFromSourceTextModifiedInJob()
UnityEngine.Debug.Log(ro.ToString());
});

a.Dispose();

Assert.IsTrue(allocator.WasUsed);
allocator.Dispose();
}
Expand Down Expand Up @@ -951,6 +954,9 @@ public void NativeTextReadOnlyThrowWhenUsingReadOnlyInJobAfterSourceHasBeenDispo
a.Dispose();
});

handle.Complete();
a.Dispose();

Assert.IsTrue(allocator.WasUsed);
allocator.Dispose();
}
Expand Down
30 changes: 16 additions & 14 deletions Unity.Collections.Tests/UnsafeListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,37 +186,39 @@ public void UnsafeListT_AddReplicate()
[Test]
public unsafe void UnsafeListT_AddNoResize()
{
var list = new UnsafeList<int>(1, Allocator.Persistent, NativeArrayOptions.ClearMemory);
var container = new UnsafeList<int>(1, Allocator.Persistent, NativeArrayOptions.ClearMemory);

// List's capacity is always cache-line aligned, number of items fills up whole cache-line.
int[] range = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };

#if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
Assert.Throws<InvalidOperationException>(() => { fixed (int* r = range) list.AddRangeNoResize(r, 17); });
Assert.Throws<InvalidOperationException>(() => { fixed (int* r = range) container.AddRangeNoResize(r, 17); });
#endif

list.SetCapacity(17);
Assert.DoesNotThrow(() => { fixed (int* r = range) list.AddRangeNoResize(r, 17); });
container.SetCapacity(17);
Assert.DoesNotThrow(() => { fixed (int* r = range) container.AddRangeNoResize(r, 17); });

list.Length = 16;
list.TrimExcess();
container.Length = 16;
container.TrimExcess();

#if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
Assert.Throws<InvalidOperationException>(() => { list.AddNoResize(16); });
Assert.Throws<InvalidOperationException>(() => { container.AddNoResize(16); });
#endif

container.Dispose();
}

[Test]
public unsafe void UnsafeListT_AddNoResize_Read()
{
var list = new UnsafeList<int>(4, Allocator.Persistent, NativeArrayOptions.ClearMemory);
list.AddNoResize(4);
list.AddNoResize(6);
list.AddNoResize(4);
list.AddNoResize(9);
Expected(ref list, 4, new int[] { 4, 6, 4, 9 });
var container = new UnsafeList<int>(4, Allocator.Persistent, NativeArrayOptions.ClearMemory);
container.AddNoResize(4);
container.AddNoResize(6);
container.AddNoResize(4);
container.AddNoResize(9);
Expected(ref container, 4, new int[] { 4, 6, 4, 9 });

list.Dispose();
container.Dispose();
}

[Test]
Expand Down
2 changes: 2 additions & 0 deletions Unity.Collections/AllocatorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ internal void InvalidateDependents()
}
}
ChildSafetyHandles.Clear();
ChildSafetyHandles.TrimExcess();
ChildSpinLock.Release();
#endif
if (Parent.IsValid)
Expand All @@ -515,6 +516,7 @@ internal void InvalidateDependents()
}
}
ChildAllocators.Clear();
ChildAllocators.TrimExcess();
}

#endif
Expand Down
Loading

0 comments on commit 6aad0ee

Please sign in to comment.