Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Linux binary -batchmode screenshots are all grey in 2019.2.x binary

Discussion in 'General Graphics' started by econt, Jan 15, 2020.

  1. econt

    econt

    Joined:
    Apr 8, 2019
    Posts:
    42
    Hi,

    there might be a bug in 2019.2.13.f1 and 2019.2.17f1 and probably the other 2019.2.x versions.
    Here is the Problem: When making a binary for Linux. It is not possible to render screenshots in batchmode (not headless, not serverbuild - there is a difference) like in 2019.1.x and 2019.3.x. The output is in all screenshots grey.

    When using the same script and a project it is possible to render screenshots in Linux binary -batchmode when making the binary with 2019.1.x and 2019.3.0f3 for example.

    Here is the way to reproduce the problem:
    1. Make a new project with e.g. 2019.2.13f1 or 2019.2.17f1
    2. add a primitive like a box
    3. add a script to your camera that save screenshots to a file (you can take any other code - my code see below, I tried different other functions and scripts)
    4. make a Linux build (settings display resolution dialog off; no server build)
    5. start binary with parameter -batchmode (not headless)
    6. look at the screenshots > they are not showing anything but one color (grey)

    Do the same with 2019.1.11f1 or 2019.3.0f3 and the screenshots show what they should show (your camera view the primitive with the skybox...)

    Please let me know if you could reproduce and if there is a way to make screenshots on Linux -batchmode (not serverbuild and not -headless) with 2019.2.x like it works on 2019.3.x and 2019.2.x?

    Thanks in Advance



    Here is the code - you can use any other to try to get the wished result:
    using UnityEngine;
    using System.Collections;
    using System;
    using System.IO;
    using System.Threading;

    public class Screenshotter : MonoBehaviour
    {


    private Camera screenshotCamera;
    private int resWidth = 1920;
    private int resHeight = 1080;
    private string path, directory;
    private bool takeHiResShot = false;
    private int counter = 0;
    public RenderTexture rt;
    Texture2D screenShot;
    private Thread screenshotThread;
    private Timer TTimer;
    private bool _threadRunning, canTakeScreenshot;
    private float timeCount;
    public float delayTime = 0.5f;
    void Start()
    {
    screenshotCamera = GetComponent<Camera>();
    CreateScreenshotDirectory();
    InvokeRepeating("TakeHiResShot", 0.04f, 0.04f);
    }

    public string ScreenShotName()
    {
    counter++;
    return System.IO.Path.Combine(directory, screenshotCamera.name + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "_" + counter.ToString() + ".jpg");
    }
    private void CreateScreenshotDirectory()
    {
    var dir = Application.dataPath + "/../Screenshots/" + screenshotCamera.name;
    string _directory = System.IO.Path.GetFullPath(dir);
    try
    {
    // Determine whether the directory exists.
    if (Directory.Exists(_directory))
    {
    Console.WriteLine("That path exists already.");

    }
    else
    {
    DirectoryInfo di = Directory.CreateDirectory(_directory);
    }
    path = _directory + "/";
    directory = System.IO.Path.GetFullPath(path);

    }
    catch (Exception e)
    {
    Console.WriteLine("The process failed: {0}", e.ToString());
    }

    }

    public void TakeHiResShot()
    {
    takeHiResShot = true;
    }

    private void TakeScreenshot()
    {
    rt = new RenderTexture(resWidth, resHeight, 24);
    screenshotCamera.targetTexture = rt;
    screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
    screenshotCamera.Render();
    RenderTexture.active = rt;
    screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
    screenshotCamera.targetTexture = null;
    RenderTexture.active = null; // JC: added to avoid errors
    Destroy(rt);
    byte[] bytes = screenShot.EncodeToJPG();
    string filename = ScreenShotName();
    System.IO.File.WriteAllBytes(filename, bytes);
    Debug.Log(string.Format("Took screenshot to: {0}", filename));
    Debug.Log("In privat void TakeScreenshot");
    takeHiResShot = false;
    }


    void LateUpdate()
    {

    if (takeHiResShot)
    {
    TakeScreenshot();
    }
    }
    }
     
unityunity