Arfoundation-samples: AR Scene Switches crash AR(Black screen)

Created on 30 Jan 2019  路  21Comments  路  Source: Unity-Technologies/arfoundation-samples

When we are using AR Foundation, while trying to switch between AR Scenes, we see black screen in 2nd,3rd... scenes. AR only works in first scene( in terms of order, not a scene specific issue). So when we look through logs, it appears to be arsubsystems crash when we change scenes on iOS only. It works on ARCore(Android) regardless. We think sessions are not restarted between scene switches. We need a fix.

Most helpful comment

I've experienced this problem with Unity 2019.1.
To make the problem reproduced, I've added a button "Reload" the "SimpleAR" sample scene that just load the same "SimpleAR" scene. After reloading, the screen becomes black.

All 21 comments

when we look through logs, it appears to be arsubsystems crash when we change scenes on iOS only

Have you got a callstack for the crash?

@tdmowrer Yeah,we got a script called "ARObjectManager" and it subscribes to system state and camera subsystem this is how it crashes:
(Filename: ./Runtime/Export/Debug.bindings.h Line: 45) default 13:11:31.819171 +0000 Kwest Uploading Crash Report default 13:11:31.819687 +0000 Kwest NullReferenceException: Object reference not set to an instance of an object. 聽聽at UnityEngine.MonoBehaviour.StopCoroutine (System.Collections.IEnumerator routine) [0x00000] in <00000000000000000000000000000000>:0聽 聽聽at Kwest.AR.ARObjectManager.ARSubsystemManager_systemStateChanged (UnityEngine.XR.ARFoundation.ARSystemStateChangedEventArgs obj) [0x00000] in <00000000000000000000000000000000>:0聽 聽聽at System.Action1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0聽
聽聽at UnityEngine.XR.ARFoundation.ARSession+d__11.MoveNext () [0x00000] in <00000000000000000000000000000000>:0聽
聽聽at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0聽
聽聽at UnityEngine.GameObject.AddComponent[T] () [0x00000] in <00000000000000000000000000000000>:0聽
`

Looks like you are calling StopCoroutine(null); in

Kwest.AR.ARObjectManager.ARSubsystemManager_systemStateChanged

What does that do?

We are starting a coroutine which is responsible from waiting until arsystemstate turns to tracking to be able to spawn objects.
This is that method:
image

And in that coroutine, we are counting for a while in case off ar is not working we display that error to screen for users.

image

@tdmowrer I think problem not happens in this particular part. We've tested in a simpler project and we had the same problem regardless without having a specific script. To reproduce this issue:

  • Create two AR Scenes, add arsessionorigin prefab and arsession game object to both of those scenes.
  • Create a little script which counts time, after couple of seconds, switches to second scene.
  • Build it for iOS
  • First scene works, when it switches to second scene screen goes black.

@tdmowrer Did you guys reproduce it as well ?

@m3rt32 @tdmowrer I'm having this problem with my project right now as well. I put LoadScene in OnApplicationFocus and have the same results. Seems to happen in the sample scenes for both iOS and Android as well.

Well the thing is, when I updated my Unity version, this issue gone away(at least I couldn't address it again,yet). Which version of Unity are you using @BikutaAnkuta ?

I'm currently on 2018.3.0f2. I haven't tried to replicate the issue on another copy of unity yet, that may be something to check.

@BikutaAnkuta Yes, I think this is the problem. Try latest version which is right now 2018.3.12 , I don't know exactly but this issue seems to be fixed. But I think you should upgrade an give it a shot to confirm.

@m3rt32 Seems like upgrading to 2018.3.7 fixes the issue. I haven't tried anything between 3.0 and 3.7 to see if its fixed any sooner. Thanks for providing a solution!

I've experienced this problem with Unity 2019.1.
To make the problem reproduced, I've added a button "Reload" the "SimpleAR" sample scene that just load the same "SimpleAR" scene. After reloading, the screen becomes black.

Same here. Seems issue was not solved Unity 2019.1.

Same here. Seems issue was not solved Unity 2019.2

Experiencing the same issue with 2019.2. Tried to resolve by resetting ARSession or destroying/re-instantiating the ARSession object in Start(). Did not work.
EDIT: found some similar issues:
https://github.com/Unity-Technologies/arfoundation-samples/issues/254
https://github.com/Unity-Technologies/arfoundation-samples/issues/217
This comment clarifies which package versions are not affected:
https://github.com/Unity-Technologies/arfoundation-samples/issues/217#issuecomment-516670311

I had a temporary fix by making the gameobject with the ARSession a singleton that does not destroy on load. It fixed the issue, however it is a bit unstable. Using Unity 2019.2.0f1.
DontDestroyOnLoad(this);

i test every methods at this page
is there any other way to fixt this bug

@ehsanwwe
I'd suggest trying to always keep one ARsession and one ARsession origin through out the entire game. As in the very first scene has the ARsession and ARsession origin in a game object. Then move this game object with you in between scenes (very important not to put other ARsession and ARsession origins in the "next" scene.)

I have same problem #340
any idea?

same problem here in 2020 may :S

@mavc18 there are several issues discussed here, and there are currently no known issues with scene switching; could you describe your issue in more detail?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kennethlng picture kennethlng  路  5Comments

jessekirbs picture jessekirbs  路  5Comments

AdrienMgm picture AdrienMgm  路  5Comments

rvegele picture rvegele  路  9Comments

jBachalo picture jBachalo  路  6Comments