mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Null reference the second time when enter in a AR Scene

Open lMasc opened this issue 7 years ago • 2 comments

Note: If this is a bug or support ticket, please provide the following information:

  • Unity version: 2018.3.2f1

  • Mapbox SDK version: 2.0.0

  • The platform you're building to: Android

  • A description of what you're trying to do: When i enter for the second time to the WorldScaleAR scene, i got an error and cant call the spawn on map objects , or they got freeze when called. The error is : NullReferenceException 02-27 11:16:38.453 22084 22099 E Unity : at (wrapper managed-to-native) UnityEngine.Component.get_transform(UnityEngine.Component) 02-27 11:16:38.453 22084 22099 E Unity : at UnityARInterface.ARController.OnBeforeRender () [0x00028] in <5fb03ba66a034bbe97c0fd816f4541b3>:0 02-27 11:16:38.453 22084 22099 E Unity : at (wrapper delegate-invoke) .invoke_void() 02-27 11:16:38.453 22084 22099 E Unity : at UnityEngine.BeforeRenderHelper.Invoke () [0x00030] in <004fc436a9154f7fab4df9679445af6c>:0 02-27 11:16:38.453 22084 22099 E Unity : at UnityEngine.Application.InvokeOnBeforeRender () [0x00001] in <004fc436a9154f7fab4df9679445af6c>:0 02-27 11:16:38.453 22084 22099 E Unity :
    02-27 11:16:38.453 22084 22099 E Unity : (Filename: <5fb03ba66a034bbe97c0fd816f4541b3> Line: 0)

  • Steps to recreate the bug if appropriate: Enter to the WorldScaleAR scene (everything works fine), then go to other scene, and then go again to WorldScaleAR scene

Thanks in advance

lMasc avatar Feb 27 '19 15:02 lMasc

Have you fixed this?

nilsk123 avatar Mar 05 '19 07:03 nilsk123

@nilsk123 yes, we fixed it , but i dont think is the proper way to do it, but our solution works for our company pourposes at least. We modify the ARControler.cs sccript method "OnBeforeRender" like this: void OnBeforeRender() { m_ARInterface.UpdateCamera(m_ARCamera); try { Pose pose = new Pose(); if (m_ARInterface.TryGetPose(ref pose)) { m_ARCamera.transform.localPosition = pose.position; m_ARCamera.transform.localRotation = pose.rotation; var parent = m_ARCamera.transform.parent; if (parent != null) parent.localScale = Vector3.one * scale; } } catch { /* // See if we are on a camera if (m_ARCamera == null) m_ARCamera = GetComponent();

            // Fallback to main camera
            if (m_ARCamera == null)
                m_ARCamera = Camera.main;

            Pose pose = new Pose();
            if (m_ARInterface.TryGetPose(ref pose))
            {
                m_ARCamera.transform.localPosition = pose.position;
                m_ARCamera.transform.localRotation = pose.rotation;
                var parent = m_ARCamera.transform.parent;
                if (parent != null)
                    parent.localScale = Vector3.one * scale;
            }
            */

        }

    }

lMasc avatar Mar 05 '19 13:03 lMasc