- Home /
Unity crashes trying to get pixels and using Debug.Log
The one that is doing the crases is the one "UnityEngine.Debug.Log(R)" line in the code, if it is deleted it won't crash, but I'll have no idea how to test if it works. This also happens if I made the list variable(InputLayer) public to the inspector. In short, Unity will crash if I try to view the list variable through anything.
Code:
void Awake()
{
CurrentVidFrame = new Texture2D(608, 1080, TextureFormat.ARGB32, false);
VideoPlayer.sendFrameReadyEvents = true;
VideoPlayer.frameReady += OnNewFrame;
VideoPlayer.Play();
}
//this is gonna work as the inputs
void OnNewFrame(VideoPlayer source, long frameIdx)
{
RenderTexture.active = (RenderTexture)source.texture;
Graphics.CopyTexture((RenderTexture)source.texture, CurrentVidFrame);
//UnityEngine.Debug.Log(CurrentVidFrame);
// clear it every frame
InputLayer.Clear();
//getting each pixel (heavy as hell)
for (int i = 0; i <(720 * 1280) - 1; i++)
{
float Col = i / 720;
int columnOfFrame;
columnOfFrame = (int)Math.Floor(Col); // rounds down to get the column number of pixels
int row = i - (720 * columnOfFrame); // get the row number of the pixels
// get the pixel color from the calculated numbers
Color pixColor = CurrentVidFrame.GetPixel(row, columnOfFrame);
float R = pixColor.r * 255; // to get a value from 0 - 1
InputLayer.Add(R); // add it to the list
UnityEngine.Debug.Log(R); // and then this shitty line freezes unity
}
}
Please feel free to ask questions, I am quite stuck.
Comment
Your answer
Follow this Question
Related Questions
Texture2D GetPixel returns the same value everywhere 2 Answers
Using Texture2DArray as RenderTarget and passing data to fragment shader 2 Answers
Unity freezes temporarily when recompiling/refreshing scripts 2 Answers
Freeze when building 0 Answers
Can a Texture2D be created at runtime from a snapshot of a RenderTexture? 3 Answers