Update a Microsoft AzureSpatialAnchor not possible

女生的网名这么多〃 提交于 2020-01-14 05:40:25

问题


I develop an unity application an I am working with azure spatial anchors. I found no possibility to update a already existing cloudAnchor. I tried this:

    protected virtual async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        // Get the cloud-native anchor behavior
        CloudNativeAnchor cna = cubeInstance.GetComponent<CloudNativeAnchor>();


        // If the cloud portion of the anchor hasn't been created yet, create it
        if (cna.CloudAnchor == null) {
            cna.NativeToCloud();
        }

        // Get the cloud portion of the anchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
        //cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        while (!CloudManager.IsReadyForCreate)
        {
            await Task.Delay(330);
            float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
            Debug.Log("create Progress");
            Debug.Log(createProgress);

            if(createProgress > 1)
            {
                createProgress = 1;
            }

            feedbackText.text = $"{ createProgress: 0 %}";
            Debug.Log($"Move your device to capture more environment data: {createProgress:0%}");
        }

        bool success = false;

        feedbackText.text = "Saving...";

        try
        {
            if(currentCloudAnchor == null)
            {
                // Actually save
                await CloudManager.CreateAnchorAsync(cloudAnchor);
            } else {
                await CloudManager.Session.UpdateAnchorPropertiesAsync(cloudAnchor);
            }

            // Store
            currentCloudAnchor = cloudAnchor;

            // Success?
            success = currentCloudAnchor != null;

            if (success && !isErrorActive)
            {
                // Await override, which may perform additional tasks
                // such as storing the key in the AnchorExchanger
                await OnSaveCloudAnchorSuccessfulAsync();
            }
            else
            {
                OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            }
        }
        catch (Exception ex)
        {
            OnSaveCloudAnchorFailed(ex);
        }
    }

The first call of the method is working. A spartialAnchor in the azure cloud was created. In the second call when I want to update the anchor I first git the error:

InvalidOperationException: SpatialAnchor::SetExpirationUtcTimeMS cannot be used to change the expiration time after the SpatialAnchor has been saved to the Cloud. That functionality is not currently supported.. Request CV: . Response CV: . 08-18 01:07:09.845 31868 31927 E Unity : at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00109] in C:...\Assets\AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:5381

To get rid of it I had to remove this line:

cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

But the update of the cloud anchor is still not working. I get this error:

OnError - The specified spatial anchor is already associated with a different store

I tried also to use this line for an update

await CloudManager.CreateAnchorAsync(cloudAnchor);

I get this error:

Failed to save anchor System.InvalidOperationException: . Request CV: . Response CV: . 08-18 01:20:07.661 5849 5909 I Unity : at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00109] in C:...\Assets\AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:5381 08-18 01:20:07.661 5849 5909 I Unity : at Microsoft.Azure.SpatialAnchors.CloudSpatialAnchorSession+<>c__DisplayClass71_0.b__0 () [0x00001] in C:\Users\ppelluda\Documents\Projects\shared-experiences-tests\Assets\AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:7162

At this moment I just see the option to delete the curent spatialAnchor in azure and create a new one. This can't be the correct approach.

What is the correct approach to update an anchor?


回答1:


This question/problem has been posed before, so I can update you on the answer. Currently there is no way to update an already existing anchor. You will need to delete the old anchor and create a new one.



来源:https://stackoverflow.com/questions/57569981/update-a-microsoft-azurespatialanchor-not-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!