Question by
vrajspandya · Jul 02, 2016 at 02:40 PM ·
webglwebcamtexturewebcamwebclient
WebCamTexture nullpointerexception
I am trying to build an app which uses webcam.
I am applying the webCamTexture on a raw image.
I am trying to run this on webGL.
I have done all the fact checks and applied all the safety checks.
public RawImage rawimage;
void Start () {
WebCamDevice backCameraDevice;
Debug.Log("code started");
WebCamDevice[] devices = WebCamTexture.devices;
for (int i = 0; i < devices.Length; i++)
Debug.Log(devices[i].name);
if (WebCamTexture.devices.Length == 0)
{
Debug.Log("No devices cameras found");
return;
}
backCameraDevice = WebCamTexture.devices[0];
Debug.Log(backCameraDevice.name);
WebCamTexture webcamTexture = new WebCamTexture(backCameraDevice.name);
webcamTexture.requestedWidth = 150;
webcamTexture.requestedHeight = 150;
rawimage.texture = webcamTexture;
rawimage.material.mainTexture = webcamTexture;
webcamTexture.Play();
}
I am getting a null pointer exception when I try to run this.
Any help would be great. Please let me know how can I provide more information if needed
Comment
Answer by sandy96 · Mar 27, 2019 at 04:51 AM
change the
WebCamDevice[] devices = WebCamTexture.devices;
to
WebCamDevice[] device = WebCamTexture.devices;