Hi I am getting this error when running my program, very randomly and I am not sure what is causing the problem.
I have a suspicion that it is because of this line:
NativeArray<Color32> texturePixels = texture.GetPixelData<Color32>(0); // this line
var deltaTime = Time.DeltaTime;
Entities.ForEach((ref PixelEntity pixelEntity, ref RequiresUpdate update, ref Timer updateTimer) =>
{
I am wondering if the NativeArray that is generated from .GetPixelData<Color32>(0) is persistent or not? Does it somehow get deallocated?
So reading the documentation it doesn’t say if it is persistent or not but it does say:
GetPixelData does not allocate memory; the returned NativeArray directly points to the Texture system memory data buffer.
So I am guessing it is persistent. I am thinking that I must be holding onto the array for too long before using the Apply() call. and therefore hitting this error.
It is recommended to immediately use or modify the data retrieved by this method and to not store the returned array for later use as the returned array can become invalid (i.e. it no longer points to valid memory) if the Texture is modified or updated after you called this method.
===============================================
Hmm its calling the error on line 19:
UpdateCellsSystem.OnUpdate () (at Assets/Scripts/Systems/UpdateCellsSystem.cs:19)
which is this line:
Entities.ForEach((ref PixelEntity pixelEntity, ref RequiresUpdate update, ref Timer updateTimer) =>