arcore-unity-extensions icon indicating copy to clipboard operation
arcore-unity-extensions copied to clipboard

Null Refrence Exception in ARSessionExtensions when running in editor

Open survivann opened this issue 6 years ago • 4 comments

With Android selected as the platform, I get an NullReferenceException every frame when running in editor.

NullReferenceException: Object reference not set to an instance of an object
Google.XR.ARCoreExtensions.Internal.ARSessionExtensions.SessionHandle (UnityEngine.XR.ARFoundation.ARSession session) (at Library/PackageCache/com.google.ar.core.arfoundation.extensions@a6a358c9d6f4-1585901453915/Runtime/Scripts/Internal/ARCoreHandles/ARSessionExtensions.cs:32)
Google.XR.ARCoreExtensions.ARCoreExtensions.Update () (at Library/PackageCache/com.google.ar.core.arfoundation.extensions@a6a358c9d6f4-1585901453915/Runtime/Scripts/ARCoreExtensions.cs:146)

This can be fixed in ARCoreExtensions by adding a UNITY_EDITOR preprocessor directive. Could someone with repo permissions review/fix? ARCoreExtensions.cs line 142:

        public void Update()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Ensure Cloud Anchors are enabled or disabled as requested.
            IntPtr sessionHandle = Session.SessionHandle();
            if (sessionHandle != IntPtr.Zero)
            {
                SessionApi.EnableCloudAnchors(
                    sessionHandle,
                    ARCoreExtensionsConfig.EnableCloudAnchors);
            }
#endif
        }

survivann avatar Apr 06 '20 14:04 survivann

Thanks for the report.

fredsa avatar Apr 06 '20 19:04 fredsa

Thank you for the report, we have fixed this in our next release.

LevanaChen avatar Jul 24 '20 00:07 LevanaChen

I was having this same problem and used this fix, which got rid of the NullReferenceException. Now I have a "SessionApi does not contain a definition for EnableCloudAnchors" error. I tried changing to CloudAnchorMode but same issue. Am I missing something?

kwurz avatar Nov 19 '20 07:11 kwurz

SessionApi.EnableCloudAnchors() has been removed since v1.19 as part of deprecation of ARCoreExtensionsConfig.EnableCloudAnchors which was done in v1.20.

LevanaChen avatar Nov 30 '20 20:11 LevanaChen