MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.28k stars 21.46k forks source link

Azure Spatial Anchors, locate anchor race condition #80703

Open eirikhanssensteria opened 3 years ago

eirikhanssensteria commented 3 years ago

When locating an anchor according to the documentation, Locate a cloud spatial anchor, you should subscribe to AnchorLocated on the current session. Which works fine, except there is a race condition and if you try to use GetPose() on the foundanchor. It throws an "Didn't find the anchor" message.

The only solution is to use the SpatialAnchorManager's AnchorLocated. So our code went from: cloudManager.Session.AnchorLocated += (object sender, AnchorLocatedEventArgs args) => to cloudManager.AnchorLocated += (object sender, AnchorLocatedEventArgs args) =>

This is the versions we're using: Unity 2020.3.15f2, Azure Spatial Anchors SDK 2.10.2 Mixed Reality Toolkit Foundation 2.7.2 OpenXR Plugin 1.0.1

The solution was found in this thread and answer. https://github.com/Azure/azure-spatial-anchors-samples/issues/121#issuecomment-577574706


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

shashishailaj commented 3 years ago

@eirikhanssensteria Thank you for sharing your findings. We will engage the content team to review and update the thread.

msftradford commented 3 years ago

@eirikhanssensteria thanks for reaching out! That CloudSpatialAnchor.GetPose() extension method relies on SpatialAnchorManager and the SpatialAnchorManager must do extra work during after the CloudSpatialAnchorSession.AnchorLocated event to make the pose available. We will work on adding more detail to our docs page (#31481757).