Search Issue Tracker
By Design
Votes
0
Found in
2018.4
2020.1.0a15
Issue ID
1201731
Regression
No
Hard crash on MemoryManager::Deallocate when calling NativeArray.Dispose()
How to reproduce:
1. Open the attached project
2. Open the "SampleScene" scene
3. Enter Play Mode
4. Exit Play Mode
Actual result: Unity hard crashes.
Reproducible with: 2020.1.0a15, 2019.3.0f1, 2019.2.15f1, 2018.4.14f1.
Notes:
- NativeArray doesn't exist in 2017.4.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
Resolution Note:
Just need to change this line:
NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<float>(p, count, Allocator.Persistent);
To this:
NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<float>(p, count, Allocator.Invalid);
Changing the Allocator to Allocator.Invalid. Then the Dispose must be removed entirely.
The code is using the this pointer of a fixed layout struct as the data pointer for a new NativeArray using ConvertExistingDataToNativeArray. This is fine, but ConvertExistingDataToNativeArray doesn't allocate a new buffer, it just interprets the pointer supplied to be the array pointer. This means you need to NOT use an allocator (therefore using Invalid), and definitely don't Dispose. It's crashing because that Dispose is trying to free memory that is actually containing the struct property value on a MonoBehaviour.