• Register
0 votes
498 views

Problem :

I am trying to create the test app using unity but facing following issue:

readpixels was called to read pixels from system frame buffer, while not inside drawing frame.

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Uou should wait until the end of the current frame encounters before taking the screenshot or before calling the function Texture2D.ReadPixels . This should be done with the WaitForEndOfFrame class. Please note  how I cached it to avoid the creation of new Object every time the function TakeSnapshot  is called.

e.g.

WaitForEndOfFrame frameEnd = new WaitForEndOfFrame();

public IEnumerator TakeSnapshot(int width, int height)
{
yield return frameEnd;
Texture2D texture = new Texture2D(800, 800, TextureFormat.RGB24, true);
texture.ReadPixels(new Rect(0, 0, 800, 800), 0, 0);
    texture.LoadRawTextureData(texture.GetRawTextureData());
texture.Apply();
sendTexture(texture, messageToSend);
}
This should fix your issue.
9 7 4
38,600 points

Related questions

0 votes
2 answers 735 views
735 views
Problem : I am new to Unity5. I am facing following error while trying to do setDestination. "SetDestination" can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:SetDestination(Vector3) CompleteProject.EnemyMovement:Update() (at Assets/ ... ; } } } } May I know what is wrong with the above code? Does anyone have any solution on my issue?
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 3 views
3 views
Problem: I need someone’s help to fix it .. 7 days to die failed to read past end of stream
asked Apr 3 Ifra 24.4k points
0 votes
1 answer 326 views
326 views
Problem : I am very new to C#. I have written the below C# code. void UpdateAxis () { float myxP = Input.GetAxis ("Horizontal")*Time.deltaTime * 20; transform.Translate (Vector3(myxP,0,0));//error is here transform.position.x = Mathf.Clamp (transform. ... the above code. error : Expression denotes a type', where avariable', value' ormethod group' was expected` Kindly suggest the solution if any.
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 12 views
12 views
Problem invalidcastexception: cannot cast from source type to destination type.
asked Feb 11 charles mathews 5.5k points
0 votes
1 answer 6 views
6 views
Problem: Why I am getting this error: Object reference not set to an instance of an object - Instantiate Thanks
asked Mar 16 ummesalma 25.2k points
0 votes
1 answer 20 views
20 views
Problem: I see that I have a warning: animator is not playing an animation controller What does that mean?
asked Mar 16 ummesalma 25.2k points
0 votes
1 answer 6 views
6 views
Problem: I have a Section of code that is compiling with the error of "Not all code paths Return a Value" I have no idea how to fix this. Any Ideas?
asked Mar 16 ummesalma 25.2k points
0 votes
1 answer 433 views
433 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17, 2020 game 4.6k points
0 votes
1 answer 1 view
1 view
Problem: I am stuck with this ... Please help me that how to deal with this error? unity how to get camera to follow player
asked Apr 1 Ifra 24.4k points
0 votes
1 answer 10 views
10 views
Problem: I am creating an editor script for a certain type of component script, I'd like to access the specific component script referenced by that instance of the editor script.
asked Mar 16 ummesalma 25.2k points