Azure / azure-spatial-anchors-samples

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

Unable to Delete Cloud Anchor #390

Closed sele98 closed 1 year ago

sele98 commented 1 year ago

Description

Anchors are created and located without issues, but when I want to delete an anchor, I get this error: "The specified spatial anchor is already associated with a different store". I followed steps from Tutorial and implemented Create, Locate and Delete methods in my project accordingly. I was able to find reference of this error happening when deleting an Anchor from OnCloudAnchorLocated callback - #61, also when trying to update an existing Anchor - #58. In my case, delete action is initiated on a button click.

Steps to reproduce the issue

  1. Open Azure Session
  2. Create/Load Azure Spatial Anchor
  3. Close Azure Session
  4. Open Azure Session
  5. Delete Azure Spatial Anchor (code below)
  6. OnError event is invoked and Azure Spatial Anchor is not deleted.

Expected behavior

Anchor should be deleted from Azure Service

Screenshots

image

I'm sure cloudAnchor is not null, Log next line shows correct Id.

Development information

AR Device information

darax commented 1 year ago

Hi @sele98, can you share the log? Also, does the basic sample in this repo work properly? I get something like this when it is working:

EstablishPoseQueryProcessorStream - Creating new stream
State from DemoStepBusy to DemoStepLookForAnchor
PoseQueryProcessorStream - ReqCV: JvOuwutPT9WPoOT8RoxMug
State from DemoStepLookForAnchor to DemoStepLookingForAnchor
[ConsiderFiringLocate] Watcher 1 fired another locate operation
[HandleFeedbackUpdated] Progress for locate was made since last request: 0, fired another locate operation: true 2119739788 2119739788 -759448156
RunDiscoverAsync - Running a Discover iteration with 1 DiscoverOptions
RunDiscoverAsync - Snapshot - Counts of Cached NeighborhoodAnchors: 0. Cached SpatialAnchors: 0.
GetPropertiesAndCVladsForDesiredSpatialAnchorIdsAsync - SetDesiredSpatialAnchors count SA Id[1] NA Id[0], locate strategy[0]
GetPropertiesAndCVladsForDesiredSpatialAnchorIdsAsync - Requesting Properties for 0 SpatialAnchors.
EnsureQueryRootKnownPosesAndBlobForStreamingQuery - Created cached query root id[1], sending known poses count[0]
GetNeighborhoodDataAsync -spatialAnchorQueryRoot != spatialAnchorLocationOrigin
RunStreamingVisualPoseQueryForNotYetLocalizedNeighborhoodAnchorIdsAsync - AddKeyFrameBlobQuery of bytes[974273]
ProcessPoseQueryStreamingEventsUntilCompletion - entry
ProcessPoseQueryStreamingEventsUntilCompletion - Awaiting more stream events
PoseQueryProcessorStream - ResCV: rdKFbctE/ky4x08nL5XSVA.0
ProcessPoseQueryStreamingEventsUntilCompletion - entry
ProcessPoseQueryStreamingPropertiesEvent - [bbeeac4c-adb0-4173-87a7-825e52814c5c] was found. naid[9b0b8e19-44c6-4de7-be7f-271524f2cece]
ProcessPoseQueryStreamingEventsUntilCompletion - Awaiting more stream events
ProcessPoseQueryStreamingEventsUntilCompletion - entry
ProcessPoseQueryStreamingPoseEvent - naid[9b0b8e19-44c6-4de7-be7f-271524f2cece], wasRelocalized[1].
[AccuracyDebugging] ProcessPoseQueryStreamingPoseEvent - desiredNA: 9b0b8e19-44c6-4de7-be7f-271524f2cece, queryNAToDesiredNA: 5:AAAAgHlw6D8AAACgLlnjPwAAAGCW8cw/AAAAQAyWzb8AAAAgLiiyvwAAAID0DO8/AAAAYJxJ4z8AAAAgBWPpvwAAAEAj6bU/AAAAAOB4jb8AAACgagD4PwAAAKAISFK/AAAAAAAA8D8=, isVisualOnly: 1
ProcessPoseQueryStreamingPoseEvent - Updating SpatialAnchor [bbeeac4c-adb0-4173-87a7-825e52814c5c]/NeighborhoodAnchor [9b0b8e19-44c6-4de7-be7f-271524f2cece] with pose found by QueryNeighborhoodDataId [2029592d-8f29-40b7-b5e3-b418ff9d2df5]
Creating spatial anchor - bbeeac4c-adb0-4173-87a7-825e52814c5c
[XR] [MROpenXR][Info   ][13:17:36.267961][tid:11e8] XrSpaceProvider_CreatingSessionOriginAnchor
ProcessPoseQueryStreamingEvents - Received KeyFrameProcessingComplete event.
ProcessPoseQueryStreamingEventsUntilCompletion - DiscoverComplete successfully.
Locate pass complete
ResetPoseQueryProcessStreamAndAssociatedState()
EstablishPoseQueryProcessorStream - Creating new stream
PoseQueryProcessorStream - ReqCV: gUUIzf4wSRmZIbd/L2skeQ
State from DemoStepLookingForAnchor to DemoStepDeleteFoundAnchor
State from DemoStepDeleteFoundAnchor to DemoStepBusy
StoreAndWatcherTrackedState::TryRemoveAsync for SpatialAnchor: bbeeac4c-adb0-4173-87a7-825e52814c5c
RestClient::DeleteSpatialAnchorAsync - ReqCV: yNCsYga3R0+1xFa66lGLRw
struct SpatialServices::DeleteSpatialAnchorRequest returned HTTP 200. ReqCV: yNCsYga3R0+1xFa66lGLRw. RespCV: 7YYV3/gldU6itpPfdboL7g.0.
RestClient::DeleteSpatialAnchorAsync - HTTP Response Status Code: 200. ReqCV: yNCsYga3R0+1xFa66lGLRw. RespCV: 7YYV3/gldU6itpPfdboL7g.0.
sele98 commented 1 year ago

Thank you @darax for a quick response! I tried this sample and it works as it should. I updated package versions in my project to match ones in the sample, but it still gives me the same error. Here's the Unity log.

UnityPlayer.log

darax commented 1 year ago

Okay, I think I see the issue. I'm guessing that the GameObject anchor being passed in to DeleteAzureAnchor is from the previous session. Instead, you need to get a new reference to the anchor in the new session that is being created. One way to go about this would be:

 CloudSpatialAnchor csa = await _cloudManager.Session.GetAnchorPropertiesAsync("anchor-guid-goes-here");
await _cloudManager.DeleteAnchorAsync(csa);
sele98 commented 1 year ago

That did the trick. Thank you very much!