I have a simple function where i get the native array of my Texture2D, edit the data then apply it.
I am then trying to Get the native array from the image again to read the data to confirm its the same what i inserted previously, but i get an exception:
void Update()
{
_data = _result.GetPixelData<Vector4>(0);
for (int i = 0; i < _size * _size; i++)
{
Vector4 a = _data1[i];
Vector4 b = _data2[i];
Vector4 c = Vector4.Lerp(a, b, _t);
_data[i] = c;
}
_result.Apply();
_data = _result.GetPixelData<Vector4>(0); // error here
}
Why can’t i get the pixel data after applying in the same frame, the next frame i can do it but not the same frame?
The Apply copies/uploads the data to video memory. It should not impact the use of GetPixelData unless you call Apply(makeNoLongerReadable = true). This would remove the CPU copy that is accessed by GetPixelData.
I tried both true and false and got the same error, did you by chance see if it reproduced the same error for you? Should be able to copy paste my code with the necessary setup variables to see if it does for you.
Ran into this same issue. In my case it only happened once I started messing with processing the texture data in burst jobs, but all jobs were Completed() when calling GetPixelData on the main thread.
However apparently it was a bug that has been fixed in the meantime.
It occurs in 2021.1.14f1 but not anymore in 2021.3.2f1 (the currently actual one).
Don’t know the exact version it got fixed unfortunately.