Insertion causes memory corruption
See original GitHub issueI’ve ran a bunch of tests with different random bound setups, as well as different entity numbers, as a result -> ran into memory corruption issue:
This line https://github.com/marijnz/NativeOctree/blob/master/Assets/NativeOctree.cs#L161
UnsafeUtility.WriteArrayElement(elements->Ptr, node.firstChildIndex + node.count, incomingElements[i]);
Causes
NullReferenceException: Object reference not set to an instance of an object System.Buffer.memcpy4 (System.Byte* dest, System.Byte* src, System.Int32 size) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Buffer.Memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.String.memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) (at <eae584ce26bc40229c1b1aa476bfa589>:0) Unity.Collections.LowLevel.Unsafe.UnsafeUtility.WriteArrayElement[T] (System.Void* destination, System.Int32 index, T value) (at <42a5878ce129403083acccf18e43363f>:0)
This can be only seen when running Unity with -debugallocator command argument. Without it - this causes a hard crash upon UnsafeList Destroy call -> Free / memory deallocation.
(Tree properties - 6 depth, 16 maxLeafElements, 1000 inserting elements, and random bounds - uniform, but not int rounded)
I do not fully understand the algorithm, so if have any suggestions how to fix it - that would be great. Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Great, you could make a PR and link this issue?
Wow. Good find. That’s very likely the culprit then. At least an important fix.