WebCamTexture Pause() crashes on Android

Hi Guys,

i’m playing around with the webcamtexture on Android and maybe found a unity bug. But before posting a bugreport, i’d like to ask you guys if it’s realy a bug or maybe is there maybe a workaround.

first problem:
WebCamTexture crashes on Pause call
I created a Webcamtexture with name.

frontCameraTexture = new WebCamTexture(frontCameraDevice.name);

If i call now the ‘Pause’ method on the instance the App crashes with sigsegv and the stacktrace contains a message that it crashes on the native pause call on webcamtexture.

.../libunity.so ((WebCamTexture::Pause()+29)...

Normally that is not a real problem, because i could only use the Start()/Stop() combination of the WebCamtexture and destroy it after using, but that leads me to the second problem.

second problem:
Internal(native) Pause method is automatically called if app goes to background(home key press)
If the User moves the app to the background while a scene with a WebCamTexture is active the engine triggers the internal Pause method of the WebCamTexture with is causing the crash. It is also triggerd if a new scene is loaded and the old one unloads.

additionally infos:
Unity: 5.5.0.f3 Personal
tested on android simulator and real device(samsung)

The WebCamTexture has not to be started to trigger the crash, it’s enough to create an instance in the scene.
Also i could workaround the new scene loading crash. Before loading the new scene i called the Stop method and destroyed the webcamtexture, than wait some time (coroutine yield…) before loading the new scene. It looks like the engine need some time to cleanup the texture. After destroying the texture the crash is not triggerd while unloading the scene.
But i could not workaround the crash if the user moves the app to the background. I tried to use OnApplicationPause/OnApplicationFocus, but i looks like they run not long enougth to let the engine destroy the texture completely.

Is there a workaround for the Problems or is it a bug in the engine that has to be fixed?

maybe it’s related to bug


a note:
after additional research - it looks like it is a bug so i created a bugreport

Hello,

Did you found something to fix this issue?
Did you try the new patch?

Hi,
sorry for the late reply but i’m a bit busy.
Currently i haven’t found the time to test the new patch because of the limeted time constrainst on the project (only free time project), but found some kind of workaround before they released the patch.

Ok so here a short description of my workaround:
I have two camera textures for front and back camera.
I’m using OnApplicationPause to check if the app goes to background or comes to foreground.
In this callback i’m calling a deinit / reinit method.
If application goes to background i’m doing sothing like that in the deinit.

        frontCameraTexture.Stop ();
        backCameraTexture.Stop ();
        image.texture = null;
        image.material.mainTexture = null;
        frontCameraTexture.Play ();
        backCameraTexture.Play ();

First i stop all webcametextures, than kill reference to ui(texture) and than the important part - i’m starting all cameratextures again. The playing cameratextures are the trick, the engine calls the pause method if the level unloads but this time it does not crash, because the textures are playing and can savely be paused.

To complete my description:
If the app comes to foreground again, you have to set the ui texture for preview again and have to start the correct cameratexture you want to play. (i remember all the states in variables)
If you load a new level manualy, you have to call the deinit before because the onpause doesnt seems to work here.

Hope that helps