Hololens 未找到捕获设备错误

Hololens No Capture Device Found Error

我正在尝试使用 this Unity 教程从全息镜头拍摄照片。当我 运行 模拟器上的代码时,不会抛出任何错误并捕获图像。当 运行ning 在实际的全息镜头上时,我收到 "Access violation reading location 0x00000030." 错误。这是我运行ning

的代码
using UnityEngine;
using System.Linq;
using UnityEngine.XR.WSA.WebCam;
using System.Collections.Generic;
using System;
using Unity3dAzure.WebSockets;

public class CapturePhoto : MonoBehaviour {
  PhotoCapture photoCaptureObject = null;
  Texture2D targetTexture = null;

  [SerializeField]
  public UnityWebSocket webSocket;

  private byte[] imgData;
  private int width;
  private int height;

  public void CaptureImage() {
    Debug.Log("Get texture and resolution");
    Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
    targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
    // Create a PhotoCapture object
    PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject) {
      Debug.Log("Starting photo capture");
      photoCaptureObject = captureObject;
      CameraParameters cameraParameters = new CameraParameters();
      cameraParameters.hologramOpacity = 0.0f;
      cameraParameters.cameraResolutionWidth = cameraResolution.width;
      cameraParameters.cameraResolutionHeight = cameraResolution.height;
      cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
      width = cameraResolution.width;
      height = cameraResolution.height;
      Debug.Log("Begin taking photo");
      // Activate the camera
      photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result) {
        // Take a picture
        Debug.Log("here");
          try {
              photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
          }
          catch(Exception e) {
              Debug.Log(e.StackTrace);
          }
      });
    });
  }

  void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame) {
    Debug.Log("Converting photo to byte");
    Texture2D tex = new Texture2D(width, height, TextureFormat.BGRA32, false);
    photoCaptureFrame.UploadImageDataToTexture(tex);
    imgData = tex.EncodeToPNG();


    // Deactivate the camera
    photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
  }

  void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result) {
    Debug.Log("Sending photo");
    // Shutdown the photo capture resource
    photoCaptureObject.Dispose();
    photoCaptureObject = null;
    webSocket.SendText(Convert.ToBase64String(imgData));
  }
}

错误发生在 Debug.Log("here") 之后。 try、catch 块不会捕获错误。错误如下

[4.583826 / 199.634425] - OnWindowActivated event - CodeActivated.
The thread 0x1428 has exited with code 13430019 (0xcced03).
The thread 0x1ec has exited with code 13430017 (0xcced01).
The thread 0x6e8 has exited with code 13430018 (0xcced02).
The thread 0xf20 has exited with code 13430017 (0xcced01).
The thread 0xcfc has exited with code 13430016 (0xcced00).
The thread 0xab4 has exited with code 13430018 (0xcced02).
The thread 0x4e8 has exited with code 13430019 (0xcced03).
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Shell.ServiceHostBuilder.dll'. Cannot find or open the PDB file.
'UnityWebSocketDemo.exe' (Win32): Unloaded 'C:\Program Files\Intel\Media SDK\libmfxhw32.dll'
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\CoreMmRes.dll'. Module was built without symbols.
'UnityWebSocketDemo.exe' (Win32): Unloaded 'C:\Windows\System32\CoreMmRes.dll'
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\CoreMmRes.dll'. Module was built without symbols.

Exception thrown at 0x7723C7D2 (KernelBase.dll) in UnityWebSocketDemo.exe: WinRT originate error - 0xC00DABE0 : 'No capture devices are available.'.

Starting photo capture

(Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 43)


Begin taking photo

(Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 43)

here

(Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 43)


'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\msvproc.dll'. Cannot find or open the PDB file.
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Perception.Stub.dll'. Cannot find or open the PDB file.
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\RTMediaFrame.dll'. Cannot find or open the PDB file.
'UnityWebSocketDemo.exe' (Win32): Loaded 'C:\Windows\System32\WindowsCodecs.dll'. Cannot find or open the PDB file.
Exception thrown at 0x127887B8 (UnityPlayer.dll) in UnityWebSocketDemo.exe: 0xC0000005: Access violation reading location 0x00000030.

我浏览了论坛,试图找到答案,包括 this post,但似乎没有任何效果。我尝试使用 unity 2018.1.6、2018.2.1、2018.2.2 和 5.5.2。在播放器设置中,我启用了麦克风和网络摄像头。是否有人熟悉此错误以及如何修复它?

统一:2018.2.2 平台:UWP

更新 我能够更进一步,我从 hololens 卸载了该应用程序,重新安装它,然后手动设置麦克风以允许在 hololens.That 中访问,有时会遇到访问冲突错误。但是 OnCapturedPhotoToMemory 中的 PhotoCaptureFrame 对象为空。我认为这与 "No capture devices are available" 错误有关。

所以我发现我做错了什么。

  1. 确保在构建设置中将目标设备设置为 HoloLens
  2. 确保在播放器设置的 XR 设置下启用虚拟现实支持

我仍然认为返回的错误很奇怪,因为仍然提示用户允许程序访问网络摄像头,并且模拟器中的错误与实际 HoloLens 中的错误不匹配