microsoft / MixedReality-WorldLockingTools-Unity

Unity tools to provide a stable coordinate system anchored to the physical world.
https://microsoft.github.io/MixedReality-WorldLockingTools-Unity/README.html
MIT License
188 stars 45 forks source link

SpacePinBinder sometimes calls publisherASA.Start before ARSession is ready #282

Closed genereddick closed 2 years ago

genereddick commented 2 years ago

With WLT and ASA on iOS, the Awake function in SpacePinBinder sometimes gets called before the AR Foundation session is setup and throws an error. This seems to be random, perhaps depending on the order that Awake functions are called in Unity for that particular session.

private void Awake()
{
    var publisherASA = GetComponent<PublisherASA>();
     // When Setup is complete, publisher.IsReady will be true.
     publisherASA.Setup();
     SetSpacePinsPublisher(publisherASA);

This throws an error:

ReposeStackWalker is not supported on this platform

The full error is similar to the reported error in the link/discussion here: https://github.com/Azure/azure-spatial-anchors-samples/issues/227

I am testing a fix suggested from the above link, though I don't know if this is the best approach or how this might impact other parts of the service.

public partial class SpacePinBinder : MonoBehaviour, IBinder
{
...
        private void Awake()
        {
            if (ARSession.state == ARSessionState.SessionTracking)
            {
                var publisherASA = GetComponent<PublisherASA>();
               // When Setup is complete, publisher.IsReady will be true.
                publisherASA.Setup();
                SetSpacePinsPublisher(publisherASA);
            }
            else
            {
                ARSession.stateChanged += ARSession_stateChanged;
            }
        }

        private void ARSession_stateChanged(ARSessionStateChangedEventArgs args)
        {
            if (args.state == ARSessionState.SessionTracking)
            {
                var publisherASA = GetComponent<PublisherASA>();
                publisherASA.Setup();
                SetSpacePinsPublisher(publisherASA);

                ARSession.stateChanged -= ARSession_stateChanged;
            }
        }
fast-slow-still commented 2 years ago

@genereddick could you attach a log (or equivalent) showing the exception, hopefully with callstack etc.?

Thanks!

genereddick commented 2 years ago

Sorry, I moved away from using ASA as Internet access couldn't be guaranteed. You can close this and I'll refile if we retest using ASA.

fast-slow-still commented 2 years ago

That's fine, thanks again for the details, and please do add any additional related info you might come across.

I'm going to leave this open for now, because I think there is a legitimate issue with the startup timing between ASA and ARF on iOS. If I can identify a safe workaround, I would be happy to have it.