Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 138 forks source link

session.start() gives and error #372

Closed EmileDavidson closed 1 year ago

EmileDavidson commented 2 years ago

Description

Getting an error while trying session.start(); catched exception ->

2022/09/14 10:50:30.882 9428 9452 Error Unity System.InvalidOperationException: LogException @ D:/a/_work/1/s/SpatialServices/API/src/Android/AzureSpatialAnchorsApiNdk/Platform/ARCoreNdkPlatformSession.cpp:27, SpatialServices::ARCoreNdkPlatformSession::ARCoreNdkPlatformSession(ssc_platform_session_handle) : Assertion failed: m_platformSessionHandle != nullptr
2022/09/14 10:50:30.882 9428 9452 Error Unity CallStack:
2022/09/14 10:50:30.882 9428 9452 Error Unity ReposeStackWalker is not supported on this platform :-(.
2022/09/14 10:50:30.882 9428 9452 Error Unity   at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00000] in <00000000000000000000000000000000>:0 
2022/09/14 10:50:30.882 9428 9452 Error Unity   at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager.StartSessionAsync () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/14 10:50:30.882 9428 9452 Error Unity   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
2022/09/14 10:50:30.882 9428 9452 Error Unity   at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager.StartSessionAsync () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/14 10:50:30.882 9428 9452 Error Unity   at CreatingStateM

Steps to reproduce the issue note. it happened in the sample scene once (haven't ran a sample scene often)

Not possible to reproduce since it's random sometimes it just works other times it doesn't I also put a try-catch around it so it doesn't stop the app and made it so I could try again sometimes it works after a second try sometimes it doesn't work not even after trying it a 100 times

        /// <summary>
        /// Starts the session. If no session exists, one will be created.
        /// </summary>
        /// In order for the property <see cref="IsSessionStarted"/> and events
        /// like <see cref="SessionStarted"/> and <see cref="SessionStopped"/>
        /// to be tracked correctly, use the <see cref="StartSessionAsync"/> and
        /// <see cref="StopSession"/> methods rather than calling methods
        /// directly on the <see cref="Session"/> instance.
        /// </remarks>
        public async Task StartSessionAsync()
        {
            // Warn if already started
            if (isSessionStarted)
            {
                Debug.LogWarning($"{nameof(StartSessionAsync)} called but session is already started.");
                return;
            }

            // If no session created, create one
            if (session == null)
            {
                Debug.Log($"{nameof(StartSessionAsync)} called with but no session. Creating one.");
                await CreateSessionAsync();
            }

            // Start the session
            try
            {
                session.Start(); /* [!] error here [!] */ 
            }
            catch (Exception e)
            {
                Debug.LogError(e);

                return;
            }

            // It's started
            isSessionStarted = true;

            // request session updates
            session.SessionUpdated += OnSessionUpdated;

            // Wait for first session update
            sessionStatus = await session.GetSessionStatusAsync();

            // Notify
            OnSessionStarted();
        }

Expected behavior

This session.start() is in the StartSessionAsync() method copied from the demo so the normal session.start() logic so I can proceed with creating an anchor

Development information (please complete the following information)

AR Device information (please complete the following information):

Varnauld commented 2 years ago

Hello - thank you for submitting this issue. Assigning to @XiangyuL-Microsoft (Tracking n#41322956)

EmileDavidson commented 2 years ago

CreateSessionAsync() also gives an Error out of nowhere: this Error only happened once after retrying (without closing the application) it worked. but then session.Start() gives an error

CreateSessionAsync();

2022/09/16 10:01:28.086 25445 25474 Error Unity System.NotSupportedException: The platform is not supported.
2022/09/16 10:01:28.086 25445 25474 Error Unity   at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager.CreateSessionAsync () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity --- End of stack trace from previous location where exception was thrown ---
2022/09/16 10:01:28.086 25445 25474 Error Unity 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager.StartSessionAsync () [0x00000] in <00000000000000000000000000000000>:0 
2022/09/16 10:01:28.086 25445 25474 Error Unity   at Sy

session.Start();

2022/09/16 10:07:26.964 25445 25474 Error native E0000 00:00:1663315646.964097   25474 scheduler.cc:278] INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
2022/09/16 10:07:26.964 25445 25474 Error native Stack trace:
2022/09/16 10:07:26.964 25445 25474 Error native 
2022/09/16 10:07:26.964 25445 25474 Error native E0000 00:00:1663315646.964195   25474 normal_detector_cpu.cc:231] Error graph_->WaitUntilIdle():INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
2022/09/16 10:07:26.964 25445 25474 Error native === Source Location Trace: ===
2022/09/16 10:07:26.964 25445 25474 Error native third_party/mediapipe/framework/scheduler.cc:278
2022/09/16 10:07:26.964 25445 25474 Error native third_party/mediapipe/framework/calculator_graph.cc:845
2022/09/16 10:07:26.964 25445 25474 Error native 
VincentSchuijt-TomTom commented 1 year ago

Also experiencing this problem, any sign of a fix? +1

EmileDavidson commented 1 year ago

Also experiencing this problem, any sign of a fix? +1

Haven't taken a look into it since my post, I switched to using persistent Google Cloud Anchors.

darax commented 1 year ago

fixed in 2.14.1 (android permissions changed)

VincentSchuijt-TomTom commented 1 year ago

Awesome @darax will check it out

yishaiSilver commented 1 year ago

Hello! I am on 2.14.1 and I was still getting that error. The following fix worked for me: #227