Search Issue Tracker

Fixed in 2020.2.X

Fixed in 2019.4.X

Votes

0

Found in

2017.4

2020.2.0a8

Issue ID

1238552

Regression

No

ScreenCapture.CaptureScreenshotAsTexture() will fail and hang editor when called from outside of the player window

MacOS

-

ScreenCapture.CaptureScreenshotAsTexture() will fail and hang editor when called from outside of the player window

When using the methods in the ScreenCapture API, such as CaptureScreenshotAsTexture(), if the user calls the method from outside of the player window (from another editor window or edit mode test), on Mac the Editor will hang and on Windows the method will fail and produce the following exceptions:

CaptureScreenshot(L:0, B:0, W:1291, H:789) requested a region that exceeds the active Render Target sized [W:2560, H:30].
CaptureScreenshotAsTexture() failed to generate texture! Was method called before the 'end of frame' state was reached?
UnityEngine.StackTraceUtility:ExtractStackTrace () (at C:/Users/dominique/src/unity/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.ScreenCapture:CaptureScreenshotAsTexture (int) (at C:/Users/dominique/src/unity/Modules/ScreenCapture/ScriptBindings/ScreenCapture.bindings.cs:30)
ScreenShot:TakeScreenShot () (at Assets/ScreenShot.cs:9)
[Assets/ScreenShot.cs line 9]

Steps to reproduce-
- Create a new project and new script, or download the attached
- Ensure the script is as follows:
using UnityEditor;
using UnityEngine;
public class ScreenShot
{
[MenuItem("Test/ScreenShot")]
static void TakeScreenShot()
{
var tex = ScreenCapture.CaptureScreenshotAsTexture(1);
if (tex == null)
return;
AssetDatabase.DeleteAsset("Assets/Capture");
AssetDatabase.CreateAsset(tex, "Assets/Capture");
}
}
- Ensure the script is saved, a "Test" menu should appear in the Editor
- Menu > Test > Screenshot
- Observe that on Mac the editor will hang, and on windows the screenshot method fails and throws the noted exceptions
Note: On 17.4, the method will fail however no exceptions will be thrown.

Reproduced on: 2020.2a8 (Windows), 2019.3.8f1 (Windows), 2017.4.37f1 (Windows), 2020.1b6 (Mac),

  1. Resolution Note (fix version 2020.2):

    CaptureScreenshot() can no longer be called from outside of playmode as of 20.2a12, preventing this issue.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.