Using Burst, the Fill method of Span<bool> somehow thinks a bool has a 4 byte size 😮
If doing something such as nativeBoolArray.AsSpan().Fill(false) which seems very friendly, it will result in writing outside of the array leading to nasty bugs.
Example:
Debug.Log($"sizeof(bool)={sizeof(bool)}, UnsafeUtility.SizeOf<bool>()={UnsafeUtility.SizeOf<bool>()}");
const int size = 16;
var memory = CollectionHelper.CreateNativeArray<byte>(size, Allocator.Temp);
for (byte i = 0; i < size; i++) {
memory[i] = i;
}
var boolSpan = new Span<bool>((bool*)memory.GetUnsafePtr() + 3, 2);
Debug.Log($"boolSpan.Length={boolSpan.Length}");
boolSpan.Fill(false);
for (int i = 0; i < size; i++) {
Debug.Log($"{i}\t{memory[i]:X}");
}
Output:
Output:
sizeof(bool)=1, UnsafeUtility.SizeOf<bool>()=1
boolSpan.Length=2
0 0
1 1
2 2
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 B
12 C
13 D
14 E
15 F