[Unity 5.6.0f3] Problem crash application with webcamTexture

Hello everyone,
I am working on a project that need to open the camera and to close it after. I was working on 5.3 with my colleagues but now they need some new features/fixes from 5.6 so we merged all our work on 5.6 and we have some crash when we open the camera and we close it. I made a new project in order to test camera’s part to know if it was a problem with our application or a problem with Unity. Here is what I tried and I have crash when I close the camera. There is only one canvas with 2 buttons (play and stop) and one raw image to show the camera output.

using UnityEngine;
using UnityEngine.UI;

public class CrashCamera : MonoBehaviour {

    public RawImage mRawImage;
    private WebCamTexture mWebcam;
    WebCamDevice mWebcamDevice;


    // Use this for initialization
    void Start () {

        //mWebcamDevice = WebCamTexture.devices.First();
        //mWebcam = new WebCamTexture(mWebcamDevice.name);
        mWebcam = new WebCamTexture();

    }
  

    // Update is called once per frame
    void Update () {
      
    
    }


    public void OnCloseButton()
    {
        Debug.Log("Close Cam");
        if(mWebcam.isPlaying )
        {
          
            mWebcam.Stop();
            //Destroy(mWebcam);
            //mRawImage.texture = null;
            //Resources.UnloadUnusedAssets();
            //Caching.CleanCache();
            //System.GC.Collect();
        }
    }

    public void OnOpenButton()
    {
        Debug.Log("Open Cam");
        //mWebcam = new WebCamTexture();
        if (!mWebcam.isPlaying)
        {
            //mRawImage.texture = mWebcam;
            mWebcam.Play();
        }
    }
}

Here is what I saw on android studio when the crash occured :

I tried options like destroy the webcamTexture and make a new one when I click on Button play, put a delay before the stop with a coroutine, clear the cache with Caching.cleanCache() and calling the garbage collector myself after the stop with System.GC.collect() but none of those corrected my crash.
I’m aware I’m not the only one with this problem because I saw a lot of thread about this but everytime this crash is marked as resolved but I still have the crash.

Examples of similar threads :

Do you have some workaround to avoid this crash, is Unity working on this?
Thanks in advance for your time and your help and sorry for my english I’m not a native!

We’ve also had this issue in 5.6. No fix was found, we just leave the camera playing. Definitely not ideal, but it’s the only thing that doesn’t crash.

Oh ok thanks for your reply.

Does anyone know if Unity is aware of this bug and if they are working on it?

You can search/submit an issue: https://issuetracker.unity3d.com/

Not sure if that counts as a bug report, which you could/should/might file, too :slight_smile:

In both cases, if you include that simple scene you described, I’m sure they’d appreciate that :wink:

Ok thanks I’ll do that!