Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Daveoh · Oct 02, 2012 at 06:30 PM · texture2dreadpixels

Texture2D.ReadPixels unknown error "not inside drawing frame"

I am getting this error when running ReadPixels on a Texture2D object.

 ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
 UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32, Boolean)

The code was not erroring before so I don't know what's changed (it's a simple script, not much to go wrong). I'm using this to take a snapshot of the screen, which I then fade out to create fading transitions between cameras etc. The strange thing is it still works perfectly (the screen is successfully captured into a Texture2D object), however this error has started showing.

I've tried searching for the whole error and parts of it on Google and I can't find a single result. Can anyone shed some light on this error?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
24
Best Answer

Answer by kmeboe · Oct 02, 2012 at 06:38 PM

Have you tried putting this code into a Coroutine? Perhaps the timing of the screen capture is off, and this is causing the complaint. Give it a shot and let us know if it works.

To do this:

1) Put your screen capture code in a method, and give it the "IEnumerator" return type.

2) At the beginning of the method, add the following line (C#):

yield return new WaitForEndOfFrame();

3) Call your method like this (C#):

StartCoroutine(methodName());

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daveoh · Oct 02, 2012 at 06:41 PM 0
Share

I use it both in a coroutine and not. I don't remember any errors before for either method (since I select "pause game on error" in the console).

avatar image kmeboe · Oct 02, 2012 at 06:45 PM 0
Share

And you're getting errors even when it's called using StartCoroutine (using WaitForEndOfFrame)? That is odd indeed.

avatar image Daveoh · Oct 02, 2012 at 06:49 PM 0
Share

I tried using "yield return new WaitForEndOfFrame();", that has stopped the error occurring. I wonder why it's only just started. I guess I'll have to change the non-coroutine method to use a coroutine also. Thanks.

avatar image kmeboe · Oct 02, 2012 at 06:51 PM 0
Share

Glad it worked! Don't forget to mark the answer as accepted. :)

avatar image ThibaultD · Oct 04, 2012 at 02:04 AM 0
Share

Same error (and solution) here. I suspect the issue was simply silent before Unity 3.5.6f4.

Show more comments
avatar image
1

Answer by ArchyInf · Dec 09, 2012 at 08:53 PM

Here is a script component that should allow capturing a RenderTexture without waiting for the next main rendering to finish. Attach it to your camera and immediately after calling camera.Render(), RenderResult will contain a texture in system memory containing the render result. The works because ReadPixels is executed while the "drawing Frame" of the camera is still active.

 using UnityEngine;
 
 public class CameraCapture : MonoBehaviour
 {
     public Texture2D RenderResult;
     
     void OnPostRender () 
     {
         Camera owner = GetComponent< Camera >();
         RenderTexture target = owner.targetTexture;
         
         if( target == null )
             return; 
         
         RenderResult = new Texture2D( target.width, target.height, TextureFormat.ARGB32, true );
         Rect rect = new Rect( 0, 0, target.width, target.height );
         RenderResult.ReadPixels( rect, 0, 0, true );
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by cecarlsen · Nov 16, 2012 at 03:22 PM

I have a method that generates the error above. The method does a on time immediate render of GL graphics to a RenderTexture and onwards to a Texture2D using ReadPixels(). Is this no longer possible? Do I have to set a flag when I need a texture, then wait for the end of the frame to create it and return it to an event handler?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kmeboe · Nov 16, 2012 at 06:00 PM 0
Share

You might have problems if you're trying to immediately grab something using ReadPixels(). In my code, I have the Texture2D creation and ReadPixels() inside a coroutine. Before I perform those steps, I have a "yield return new WaitForEndOfFrame();" at the top of the coroutine to give the rendering a chance to finish.

avatar image cecarlsen · Nov 17, 2012 at 09:44 AM 0
Share

Thanks. I wonder if it is still possible somehow to render GL to a Texture2D immediately on demand. I created an example on the forum here: http://forum.unity3d.com/threads/158918-Rendering-GL-to-a-Texture2D-immediately-in-Unity4

avatar image cecarlsen · Dec 03, 2012 at 03:06 PM 0
Share

If anyone has succeeded in rendering GL to a RenderTexture in Unity4, then please view the forum thread just above.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get banner ad's screenshot to a texture? 0 Answers

Texture2D.ReadPixels ignores Sprite Mask, captures hidden sprites 0 Answers

Texture2D readPixels: How to only read a section of the camera view? 0 Answers

Can a Texture2D be created at runtime from a snapshot of a RenderTexture? 3 Answers

Only grey (205) when reading pixels from a RenderTexture to a Texture2D 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges