google-ar / arcore-unity-extensions

Google ARCore Extensions and Geospatial Creator for Unity's AR Foundation
Other
347 stars 97 forks source link

Null Refrence Exception in ARSessionExtensions when running in editor #13

Open survivann opened 4 years ago

survivann commented 4 years ago

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
        }
fredsa commented 4 years ago

Thanks for the report.

LevanaChen commented 4 years ago

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

kwurz commented 3 years ago

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?

LevanaChen commented 3 years ago

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