Hololens No Capture Device Found Error

0

I am trying to capture a photo from the hololens using this Unity tutorial. When I run the code on the emulator, no error is thrown and an image is captured. When running on the actual hololens I get a "Access violation reading location 0x00000030." error. Here is the code I am running

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));
  }
}

The error hits after the Debug.Log("here"). The try, catch blocks do not catch the error. The error is below

[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.

I have looked through forums trying to find the answer including this post, but nothing seems to work. I have tried using unity 2018.1.6, 2018.2.1, 2018.2.2, and 5.5.2. On the player settings I have microphone and webcam enabled. Is anyone familiar with this error and how it could be fixed?

Unity: 2018.2.2 Platform: UWP

UPDATE I was able to get a little further along, I uninstalled the app from the hololens, reinstalled it, then manually set the microphone to allow access in the hololens.That sometimes gets ride of the Access Violation Error. But the PhotoCaptureFrame object in OnCapturedPhotoToMemory is null. I think this is related to the "No capture devices are available" error.

c#
unity3d
hololens
asked on Stack Overflow Aug 6, 2018 by cbolles • edited Aug 6, 2018 by cbolles

1 Answer

0

So I found out what I did wrong.

  1. Make sure in the build settings to set Target Device to HoloLens
  2. Make sure to enable Virtual Reality Support under the XR Settings in the Player Settings

I still think the returned error is odd since the user is still prompted to give the program access to the webcam and that the errors in the emulator do not match up with the errors in the actual HoloLens

answered on Stack Overflow Aug 13, 2018 by cbolles

User contributions licensed under CC BY-SA 3.0