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
0
Question by Hoeloe · Mar 24, 2014 at 12:38 AM · texturetexture2dscreenshotreadpixelsapply

Texture.Apply() Crashes at Resolutions under 1920x1080

So, this is a bug that is, I must admit, "weird as hell". I have a system set up for taking a screenshot of the scene.

My code is very small, it is these few lines:

 Texture2D result;
             result = new Texture2D(Mathf.RoundToInt(captureZone.width) + destX,
                         Mathf.RoundToInt(captureZone.height) + destY,
                         TextureFormat.RGB24, false);
 
             result.ReadPixels(captureZone, destX, destY, false);
             result.Apply();
 
             return result;

Now, I'm using this to apply an effect on my screen when I pause the game. I'm capturing the screen once when pause is pressed, which is fine. I then draw that captured screen with a blur effect using Graphics.DrawTexture at a quarter its original scale. I then capture this into another texture, and draw it again to the entire screen, with the same blur effect applied again (this had minimal performance impact and allowed me to apply another blur). I then attempt to capture this last image one last time, so I can draw it directly to the screen without having to apply the filter every frame.

It is this last capture that causes problems. It is using exactly the same code as the first capture (namely, running the above code with the captureZone set to a rectangle at (0,0), spanning to Screen.width and Screen.height, and with destX and destY both set to 0. This works fine in the editor, and when I run the external build at a resolution of 1920x1080.

If I run it at any other resolution, however (regardless of aspect ratio), it immediately freezes. I have probed as much as I can and have found that the line:

 result.Apply();

is the one that is freezing the application. The build's log does not display any error messages.

Run on another computer, however, it all seems to work. I am somewhat concerned by this issue, as it seems completely nonsensical, and I have no clue what could be causing it. If anyone has any ideas, please don't hesitate to let me know!

Comment
Add comment · Show 5
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 Hoeloe · Mar 24, 2014 at 12:52 PM 0
Share

I've shuffled around the code to remove this last Apply call, and it still crashes, though now it does so in a very weird way. It seems it's calling the draw functions exactly as expected (it prints to the output log every frame if I stick a print statement in there), but it still hangs. Also, it seems that I can't run the game in full screen at all, as it resizes the display, then hangs as a background process, without even running the splash screen. This might suggest it's an issue with the player, rather than with my code.

avatar image Hoeloe · Mar 24, 2014 at 12:55 PM 0
Share

Another thing that's interesting to note is that I have multiple graphics processors on my PC, and I can explicitly run a program with a specific processor. When I do this (to ensure it is running on the right processor), it appears to use the wrong data set, and runs an older build. Not sure why this would be, either, but again might suggest a Unity issue.

avatar image Hoeloe · Mar 24, 2014 at 01:00 PM 0
Share

I managed to get it to run in full screen by moving it to a different folder from the rest of the builds. This also solved the specific processor problem. The crash, however, still remains a problem.

avatar image Hoeloe · Mar 24, 2014 at 01:08 PM 0
Share

Further news! I have tried disabling DX3D11, which has stopped it from crashing. However, it now simply does not work, and displays either a blank texture, or random noise.

avatar image Hoeloe · Mar 24, 2014 at 01:19 PM 0
Share

Update here: It still draws correctly at 1920x1080 resolution, but nothing else.

1 Reply

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

Answer by Hoeloe · Mar 24, 2014 at 02:00 PM

I fixed it! Not sure what the original bug was, but after shuffling it around a bit, I discovered that the issue was attempting to read a rectangle from the screen that had non-integer width and/or height. A simple call to RoundToInt fixed it perfectly.

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

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

20 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Screenshot as Texture 4 Answers

Application.CaptureScreenshot on a Texture2D? 1 Answer

What's wrong with my screenshot function? 1 Answer

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

ReadPixels returns RGBA(0,0,0,0) 0 Answers


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