question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insertion causes memory corruption

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
marijnzcommented, Apr 13, 2021

Great, you could make a PR and link this issue?

1reaction
marijnzcommented, Apr 13, 2021

Wow. Good find. That’s very likely the culprit then. At least an important fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vector.insert() causes memory corruption - c++
vector.insert() causes memory corruption · 1. there is missing () after the end (in the line before the last one). · how do...
Read more >
Detecting Memory Corruption Bugs With HWASan
Native code in memory-unsafe languages like C and C++ is often vulnerable to memory corruption bugs. Our data shows that issues like ...
Read more >
Memory Leak with Inserting at the End of a Singly Linked List
For some reason, according to valgrind , there's a memory leak at the following line in my insert() method: ListNode* newNode = new...
Read more >
c++ - Debugging memory corruption
Otherwise, once you find what memory has been corrupted, ... Then with back trace you can see your code that's causing the corruption....
Read more >
Memory corruption
The most likely causes of memory corruption are programming errors (software bugs). When the corrupted memory contents are used later in that program, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found