• Register
0 votes

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

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.


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);
sendTexture(texture, messageToSend);
This should fix your issue.
9 7 4
38,600 points

Related questions

0 votes
2 answers 393 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 168 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
1 vote
2 answers 50 views
Problem: I am beginner to C# with Unity engine. I have already started learning C# with Unity engine. I have tried to write the very basic script as shown below for your reference: using UnityEngine; using System.Collections; public class scriptMyBall : MonoBehaviour { / ... but unable to fix the Unity Engine related error. I need Unity Engine’s expert who can guide me in fixing above error.
asked May 23 Martin K 6.6k points
1 vote
1 answer 130 views
Problem : Looking for the solution on bellow problem setting the parent of a transform which resides in a prefab is disabled to prevent data corruption
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 36 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 game 4.6k points