获取 SceneObserver.ComputeAsync 的结果时出现 COMException
COMException when getting result of SceneObserver.ComputeAsync
我正在关注 scene understanding docs 以获得场景理解网格。这是我的代码,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;
}
}
}
问题是SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync();
。我将其移至 Init
函数,错误消失了。
我正在关注 scene understanding docs 以获得场景理解网格。这是我的代码,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;
}
}
}
问题是SceneObserverAccessStatus accessStatus = await SceneObserver.RequestAccessAsync();
。我将其移至 Init
函数,错误消失了。