COMException при получении результата SceneObserver.ComputeAsync

#c# #hololens #mrtk

#c# #hololens #mrtk

Вопрос:

Я следую документам по пониманию сцены, чтобы получить сетку понимания сцены. Вот мой код, init срабатывает при нажатии на поле с указателем.

Я получаю сообщение COMException с кодом ошибки -2147024891 , которое, по-видимому, является некоторой ошибкой отказа в доступе. Вы можете увидеть, где я перехватываю исключение.

 using Microsoft.MixedReality.SceneUnderstanding;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

public class StartSceneUnderstanding : MonoBehaviour
{
    // Start is called before the first frame update
    async void Start()
    {
        if (!SceneObserver.IsSupported()) {
            Debug.Log("Huh. SceneObserver isn't supported.");
        }
        SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync();
        Debug.Log($"Access status: {accessStatus}");
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void Init() {
        Debug.Log("Initializing scene understanding");
        // Create Query settings for the scene update
        SceneQuerySettings querySettings;

        querySettings.EnableSceneObjectQuads = true;                                       // Requests that the scene updates quads.
        querySettings.EnableSceneObjectMeshes = true;                                      // Requests that the scene updates watertight mesh data.
        querySettings.EnableOnlyObservedSceneObjects = false;                              // Do not explicitly turn off quad inference.
        querySettings.EnableWorldMesh = true;                                              // Requests a static version of the spatial mapping mesh.
        querySettings.RequestedMeshLevelOfDetail = SceneMeshLevelOfDetail.Fine;            // Requests the finest LOD of the static spatial mapping mesh.

        // Initialize a new Scene
        var x = SceneObserver.ComputeAsync(querySettings, 10.0f);
        var awaiter = SceneObserver.ComputeAsync(querySettings, 10.0f).GetAwaiter();
        try {
            Scene myScene = awaiter.GetResult();
        } catch (COMException e) {
            Debug.Log($"Failed to construct scene. Error code {e.ErrorCode}. Message:n{e.Message}");
            var a = 1;
        }
    }
}
 

Комментарии:

1. Некоторым COM-объектам не нравится, когда их создают в одном потоке и обращаются к ним в другом.

Ответ №1:

Проблема SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync(); в том. Я переместил его в Init функцию, и ошибка исчезла.