- Home /
 
Errors on accessing WebCamTexture.devices
I've been looking into integrating the device camera in a mobile app (iOS and Android), and keep coming across some errors when accessing WebCamTexture.devices.
When devices are available (i.e. on my laptop with a built-in camera and on mobile devices with cameras), the code below works just fine. However, when I run it on my desktop system (which has no camera), I get these errors in the console:
 result == noErr
 UnityEngine.WebCamTexture:get_devices()
 <Start>c__Iterator0:MoveNext() (at Assets/Scripts/Camera/WebCamera.cs:16)
 result == noErr
 UnityEngine.WebCamTexture:get_devices()
 <Start>c__Iterator0:MoveNext() (at Assets/Scripts/Camera/WebCamera.cs:18)
 
               They correspond to the lines where I am using WebCamTexture.devices. (Actually, the first of these lines is my attempt to avoid the error, which obviously doesn't work :P)
The game continues running despite this (it successfully just gets rid of the camera surface via the Destroy() call) so the errors aren't stopping the app, but I feel like it shouldn't be running with errors spewed to the console.
Now, I'm afraid I do not understand what "result == noErr" means and can't find documentation about this. Any ideas on what this issue is and how I can implement this without errors in the console?
 using UnityEngine;
 using System.Collections;
 
 // Basic code borrowed from: http://www.ikriz.nl/2011/12/23/unity-video-remake
 public class WebCamera : MonoBehaviour
 {
     private WebCamTexture webcamTexture;
     
     IEnumerator Start()
     {
         /* First we'll try to go through the list of cameras (if
          * we can) and find a suitable one (not front-facing). */
         bool foundCamera = false;
         string desiredCameraName = "";
         if (WebCamTexture.devices != null)
         {
             for (int i = 0; i < WebCamTexture.devices.Length; i++)
             {
                 // We'd like a camera which is not front-facing.
                 if (!WebCamTexture.devices[i].isFrontFacing)
                     desiredCameraName = WebCamTexture.devices[i].name;
             }
         }
         
         /* If we've got one, we try to get access and then play it. */
         if (foundCamera)
         {
             webcamTexture = new WebCamTexture(desiredCameraName);
             renderer.material.mainTexture = webcamTexture;
             
             yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
             if(Application.HasUserAuthorization(UserAuthorization.WebCam)) 
             {
                 webcamTexture.Play();
             }
         }
         else
         {
             // No camera. So sad. Time to end it.
             Destroy(gameObject);    
         }
    }
 }
 
              Hi,
I am running into the same issue, when I try to access the device list when there is no device available. I need to access that list even if empty, at least to know it's empty... Did you filled a bug to unity?
Answer by Jason-RT-Bond · Jun 21, 2012 at 09:07 PM
I've just reported this to Unity Tech. It seems like a fairly minor issue, but it would be nice if this worked without the weird error spew.
Seems to be corrected in the latest version of Unity (4.0.1).
Your answer