Search Unity

Bug "Screen position out of view frustum" Error help

Discussion in 'Editor & General Support' started by gplex130, Oct 29, 2022.

  1. gplex130

    gplex130

    Joined:
    Jan 20, 2022
    Posts:
    4
    This error has been driving me insane. When I would test my game by building and running, occasionally I would just be playing the game and then my player character would be destroyed and the cam would flip from the player camera to another camera on my map, and this would only ever happen when the game is built, never when it's run in the editor.

    Eventually I decided to figure out why this was happening so I set up a text area and had the console write to it, so I could see the output while it was playing the build. And whenever that error would occur, the output would be continuously flooded with the error:

    Screen position out of view frustum (screen pos 959.000000, 540.000000) (Camera rect 0 0 1920 1080)

    the clipping planes on every camera, including the player camera, are
    Near: 0.5
    Far: 1000
    I have not set up any scripts that mess with the FOV at all, it is a perspective camera, the player camera is tagged as the "Main Camera", it is a 3D game, there is never a clear action that causes this error, it seems to just trigger randomly, sometimes it does it within seconds, other times it takes several minutes, and it only happens when the game is built, never when it is run in the editor.

    Has anyone dealt with anything similar to this or have any potential fixes, I have been wrestling with this error for days and nothing I've tried has worked.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    One random idea: check if you are parenting the camera to the player, then setting the player's scale to zero when you kill him. In general, never ever set any element of the scale of any Transfor to zero.

    The proper way to set scales:

    https://forum.unity.com/threads/onpointerenter-loose-image.1152686/#post-7396073

    NEVER set scale (or any part of scale) to zero or negative.

    NEVER use Vector2 because that makes the third term (Z) zero.

    ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.

    Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy.
     
  3. gplex130

    gplex130

    Joined:
    Jan 20, 2022
    Posts:
    4
    Hmm, I don't think there's ever any point in my code where change the scale of the player, UI elements, or any of their children, and the only vector 2 I've used in the entire project is for storing the horizontal and vertical mouse movements, but thanks for the advice, I'll keep that in mind while I keep searching.
     
  4. gplex130

    gplex130

    Joined:
    Jan 20, 2022
    Posts:
    4
    Update

    I've tried some more solutions, none have worked.

    I've made it so it prints the local scale, FOV, far clip plane, near clip plane, and rect of both the player camera and the weapon model camera to the console, and neither change at all before or after the error hits.

    I've tried having the build run as windowed, maximized window, full screen window, exclusive full screen, no differences.

    I've tried messing with the scaling of the UI, making it constant pixel size, constant physical size, stretch, no difference.

    I've tried deleting and remaking both cameras from scratch, no difference.

    It still only happens when the game is built, and there still seems to be no clear trigger, sometimes it waits several minutes before doing the error, other times it does it near instantly.

    Finally, I opened the log file to find the output of the error there to see if it would give any more detailed information, and it reads:

    [C:\buildslave\unity\build\Runtime\Camera\Camera.cpp line 3554]

    Screen position out of view frustum (screen pos 959.000000, 540.000000) (Camera rect 0 0 1920 1080)
    UnityEngine.StackTraceUtility:ExtractStackTrace () (at C:/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
    UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector2,UnityEngine.Camera/MonoOrStereoscopicEye)
    UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector3,UnityEngine.Camera/MonoOrStereoscopicEye) (at C:/buildslave/unity/build/Runtime/Export/Camera/Camera.bindings.cs:169)
    UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector3) (at C:/buildslave/unity/build/Runtime/Export/Camera/Camera.bindings.cs:170)
    UnityEngine.SendMouseEvents:DoSendMouseEvents (int) (at C:/buildslave/unity/build/Modules/InputLegacy/MouseEvents.cs:167)
     
  5. gplex130

    gplex130

    Joined:
    Jan 20, 2022
    Posts:
    4
    Update number the second one:

    After setting it up to output the rect, far plane, near plane, FOV, and scale of the 2 cameras, as well as the current screen position, they still look fine even after the error hits. Hell, the output even says that the screen pos is still at (0, 0), contradicting the error saying it is not.
     

    Attached Files:

  6. Techyte

    Techyte

    Joined:
    Apr 3, 2021
    Posts:
    4
    Hi! I have been experiencing the exact same problem for months with my game. Only happens in builds, happens at random times and everything seems to be in perfect working order. I am wondering if you have found a potential solution?
     
  7. jamailun

    jamailun

    Joined:
    Feb 16, 2019
    Posts:
    1
    Hello, same problem here. I'm using Unity 2021.3 and the built game randomly creates those "Screen position out of view frustum". Same context as the author: I don't touch the scale of the player or anything: it just happens randomly.
     
  8. Gilles_Baroin

    Gilles_Baroin

    Joined:
    Jan 26, 2022
    Posts:
    7
    Workout: if you can not find the cause, and Unity does not catch the Errors
    I have a scripted "portal camera" that sometimes generated Frustrum errors
    Game was pausing in editor mode, I had to click pause to resume.
    Compiled version was running

    in my Case, I had random frustrum errors, in editor mode
    I check for NaN in the Frustrum Corners before rendering
    This does not solve the original problem but avoid rendering "bad frames"
    Cheers


    // avoid frustrum on Corners
    Vector3[] frustumCorners = new Vector3[4];

    // Calculate Corners for my portalCamera :
    portalCamera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), portalCamera.farClipPlane, Camera.MonoOrStereoscopicEye.Mono, frustumCorners);

    // Check for NaN in any of the 4 vectors (checking x is enough since NaN occurs in all 3 components)
    for (int i = 0; i < 4; i++)
    if (float.IsNaN(frustumCorners.x))
    {
    Debug.Log("Frustrum NaN on Vector #" + i);
    FrustumError = true;
    }

    // Render if no NaN found

    if (!FrustumError)
    try
    {
    portalCamera.Render();
    }
    catch (Exception e)
    {
    Debug.LogWarning("Frustrum catched despite checking");
    }
     
    Last edited: Nov 18, 2023