Camera not restarting in Android built from Unity

0 votes
asked Oct 19 by thedapperlab (240 points)
Hi, hope someone can help...

We're developing an app which launches an AR view from time to time.  In Unity Editor it works fine, but on an Android device (iOS not tested yet) it works fine the first time, but we get Exceptions every frame when relaunching (see below).

Interestingly, restarting the app quickly also exhibits the same problem (exceptions, no video rendered onto Render Texture).   After a while it works fine again the first time.  I'm assuming therefore it's something up with releasing the video camera device, or similar, but would appreciate some hints on where to look for the cause...

The errors we're seeing on the device look like this:

2022/10/18 15:14:06.850 14664 14712 Error Unity NullReferenceException: Object reference not set to an instance of an object
2022/10/18 15:14:06.850 14664 14712 Error Unity   at UnityEngine.AndroidJavaObject._Call[ReturnType] (System.String methodName, System.Object[] args) [0x0000f] in <157db3d40e194fc2b8370dbe68a88be2>:0
2022/10/18 15:14:06.850 14664 14712 Error Unity   at UnityEngine.AndroidJavaObject.Call[ReturnType] (System.String methodName, System.Object[] args) [0x00001] in <157db3d40e194fc2b8370dbe68a88be2>:0
2022/10/18 15:14:06.850 14664 14712 Error Unity   at easyar.Display.get_Rotation () [0x00018] in <fefcd206b4654fe9961e2f3e0dcd1ef9>:0
2022/10/18 15:14:06.850 14664 14712 Error Unity   at easyar.ARSession.GetCompensation (easyar.CameraParameters camParams) [0x0000c] in <fefcd206b4654fe9961e2f3e0dcd1ef9>:0
2022/10/18 15:14:06.850 14664 14712 Error Unity   at easyar.ARSession.Update () [0x000bd] in <fefcd206b4654fe9961e2f3e0dcd1ef9>:0

We're using the EasyAR_ImageTracker prefab as the basis of our implementation.

Many thanks in advance for any and all help!

Dom

1 Answer

0 votes
answered Oct 21 by thedapperlab (240 points)
Solved.

Wasn't so much a camera issue as an ARSession issue.  We were destroying one ARSession and then immediatelt launching another - turned out there was a race condition with the old one disposing the device camera after the new one had started it.

Fixed with a simple yield until old object null.
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...