Topic: Issue with: "Screen position out of view frustum" in Navigation exampl

Hello,

I'm encountering a persistent error when trying out the "Navigation" example scene in Online Maps v3 (v3.9.3.1) in Unity editor 2022.3.28f1 on the Android platform. The issue arises specifically with a screen position error related to the camera's view frustum. Here's the error message I receive:

Screen position out of view frustum (screen pos inf, -inf) (Camera rect 0 0 1080 2340)

This error is followed by a series of call stacks that seem to involve Camera::ScreenPointToRay and related methods. Here is a part of the call stack:

0x00007ff7ab708e5d (Unity) StackWalker::GetCurrentCallstack
0x00007ff7ab70df29 (Unity) StackWalker::ShowCallstack
0x00007ff7ac6f2a21 (Unity) GetStacktrace
...
0x00000230acf3b5eb (Mono JIT Code) OnlineMapsTileSetControl:HitTest (UnityEngine.Vector2) (Infinity Code/Online maps/Scripts/Controls/3D/OnlineMapsTileSetControl.cs:458)

I have checked my camera settings and scene setup but haven't found any discrepancies that might cause this. Could anyone please help me understand what might be going wrong or how to resolve this error?

Re: Issue with: "Screen position out of view frustum" in Navigation exampl

Hello.

This error usually happens when the screen width or height is zero.
But HitTest method has a check for this case.

Try wrapping the contents of the OnlineMapsTileSetControl:HitTest method in try/catch, and log the value of the position parameter when the exception happens.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Issue with: "Screen position out of view frustum" in Navigation exampl

Hello,

Thank you for your suggestions. I've implemented additional logging and checks in the HitTest method to catch invalid screen positions before calling ScreenPointToRay. Here's the updated method:

    protected override bool HitTest(Vector2 position)
    {
        try
        {
#if NGUI
        if (UICamera.Raycast(position)) return false;
#endif
            Rect rect = currentCamera.rect;
            if (rect.width == 0 || rect.height == 0) return false;
            if (position.x < 0 || position.y < 0 || position.x > Screen.width || position.y > Screen.height)
            {
                Debug.Log($"HitTest error! Position: {position.x}, {position.y}");
            }
            return cl.Raycast(currentCamera.ScreenPointToRay(position), out lastRaycastHit, OnlineMapsUtils.maxRaycastDistance);
        } 
        catch (Exception e)
        {
            Debug.Log($"HitTest error! Position: {position.x}, {position.y}");
            return false;
        }
    }

With these changes, the console now outputs the following when the error occurs:

HitTest error! Position: Infinity, Infinity

It appears the position sometimes becomes infinite, which likely causes the out-of-view frustum error. However, even with these checks, the issue persists and the try/catch block isn't catching exceptions as expected, perhaps due to the nature of errors coming from lower-level or native Unity code.

Could you advise on any further steps I might take to handle or prevent Infinity positions or suggest any modifications that could help resolve this error?

Re: Issue with: "Screen position out of view frustum" in Navigation exampl

Add this line to the beginning of the method and the problem will be solved:

if (float.IsInfinity(position.x) || float.IsInfinity(position.y)) return false;

If possible, please send me the full stack trace of the exception so I can check why this is happening.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Issue with: "Screen position out of view frustum" in Navigation exampl

I also noticed that these errors do not occur in Unity version 2022.3.11f1, suggesting that the issue might be specific to the Unity version I am currently using.

Here is the full stack trace from the exception:

Screen position out of view frustum (screen pos inf, -inf) (Camera rect 0 0 1024 2048)
0x00007ff60aaf8e5d (Unity) StackWalker::GetCurrentCallstack
0x00007ff60aafdf29 (Unity) StackWalker::ShowCallstack
0x00007ff60bae2a21 (Unity) GetStacktrace
0x00007ff60c19cebe (Unity) DebugStringToFile
0x00007ff60a405be5 (Unity) Camera::ScreenPointToRay
0x00007ff609a0cf9f (Unity) Camera_CUSTOM_ScreenPointToRay_Injected
0x00000237b72e1faa (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Camera:ScreenPointToRay_Injected (UnityEngine.Camera,UnityEngine.Vector2&,UnityEngine.Camera/MonoOrStereoscopicEye,UnityEngine.Ray&)
0x00000237b72e1e7b (Mono JIT Code) UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector2,UnityEngine.Camera/MonoOrStereoscopicEye)
0x00000237b72e1db3 (Mono JIT Code) UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector3,UnityEngine.Camera/MonoOrStereoscopicEye)
0x00000237b72e1ca3 (Mono JIT Code) UnityEngine.Camera:ScreenPointToRay (UnityEngine.Vector3)
0x00000237b72e150b (Mono JIT Code) OnlineMapsTileSetControl:HitTest (UnityEngine.Vector2) (at .../Assets/Infinity Code/Online maps/Scripts/Controls/3D/OnlineMapsTileSetControl.cs:464)
0x00000237b72e0fd7 (Mono JIT Code) OnlineMapsControlBase:HitTest () (at .../Assets/Infinity Code/Online maps/Scripts/Controls/Base/OnlineMapsControlBase.cs:622)
0x00000237b72e0c8b (Mono JIT Code) OnlineMapsControlBase:UpdateZoom () (at  .../Assets/Infinity Code/Online maps/Scripts/Controls/Base/OnlineMapsControlBase.cs:1313)
0x00000237b72e07e3 (Mono JIT Code) OnlineMapsControlBase:ProcessInteractions () (at .../Assets/Infinity Code/Online maps/Scripts/Controls/Base/OnlineMapsControlBase.cs:1067)
0x00000237b72e0633 (Mono JIT Code) OnlineMapsControlBase:Update () (at .../Assets/Infinity Code/Online maps/Scripts/Controls/Base/OnlineMapsControlBase.cs:1144)
0x00000237b723f628 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ff825e24c1e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ff825d5d254 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3068)
0x00007ff825d5d3cc (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3115)
0x00007ff60aa11ba4 (Unity) scripting_method_invoke
0x00007ff60a9ef914 (Unity) ScriptingInvocation::Invoke
0x00007ff60a9d7104 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff60a9d722a (Unity) MonoBehaviour::CallUpdateMethod
0x00007ff60a46a1fb (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00007ff60a47177a (Unity) BehaviourManager::Update
0x00007ff60a6a6e7d (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x00007ff60a685f8c (Unity) ExecutePlayerLoop
0x00007ff60a686100 (Unity) ExecutePlayerLoop
0x00007ff60a68c995 (Unity) PlayerLoop
0x00007ff60b66228f (Unity) PlayerLoopController::InternalUpdateScene
0x00007ff60b66f0bd (Unity) PlayerLoopController::UpdateSceneIfNeededFromMainLoop
0x00007ff60b66d3a1 (Unity) Application::TickTimer
0x00007ff60bae86ca (Unity) MainMessageLoop
0x00007ff60baed5a0 (Unity) WinMain
0x00007ff60ced0aae (Unity) __scrt_common_main_seh
0x00007ff8cd47257d (KERNEL32) BaseThreadInitThunk
0x00007ff8cdd4aa48 (ntdll) RtlUserThreadStart

Re: Issue with: "Screen position out of view frustum" in Navigation exampl

Thanks for the stack trace.
I have tested and the infinity comes from Input.mousePosition (Unity API).
It looks like some bug in Unity Engine.
On my side I can't fix this bug, only add an extra check to OnlineMapsControlBase.GetInputPosition to prevent exceptions.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.