Issue with Android: Skipped rendering frame because GfxDevice is in invalid state (device lost)

We’re having serious issues with the Unity 2022 LTS versions and this is blocking work for us.

What are the steps to create a working XR project in Unity now?
The issue is a black screen on Android devices. Sometimes we can get a project to work by deleting Library, removing and reinstalling all XR packages but even then it often later fails on another machine until the steps are repeated.

You can reproduce the issue with these steps:

  • Create a new project in Unity 2022.3.2f1 (or any other LTS version) with the 3D template
  • Install the Universal RP package through Package Manager
  • Create the Universal Render Pipeline Asset and Renderer and add the ARBackgroundRendererFeature
  • Install the AR package collection (5 in total) through Package Manager
  • Add the AR Session and XR Origin (Mobile AR) setup to the default SampleScene and remember to delete MainCamera
  • Remove Vulkan from Graphics API, set Minimum API Level to 24, change Target Architecture to ARM64
  • Build for Android

The app will open with a black screen with my test phone with Android 11 and errors. The log is attached to this post. Curiously locking the screen and reopening the device seems to help.

To fix this:

  • Remove all AR packages
  • Close Unity, delete Library,
  • Install only Google ARCore XR Plugin
  • Build for Android

The errors are gone and everything works.
How can we set up the project so it could also support Magic Leap?

9083125–1257400–adb-log.txt (4.21 KB)

1 Like

Also, what’s up with the jello effect when using the new XR Origin instead of the deprecated AR Session Origin?

There’s a noticeable jello effect with Android devices where AR content follows a frame or a few late behind the camera image. I have video footage if it’s needed but I’ve seen this happening on all Android builds if they are upgraded to use XR Origin.

I’ll file a bug report but would be nice to know if others experience this issue too. Happens with all 2022 LTS versions of Unity.

Found this thread about the jello effect issue [Bug] ARFoundation 5.0.2 drift issue · Issue #1063 · Unity-Technologies/arfoundation-samples · GitHub

Still trying to figure out how to best support Android and Magic Leap 2 in one project

1 Like

I don’t know the answer to your issue offhand. Do you have the same results on Android when you convert our sample app to URP? GitHub - Unity-Technologies/arfoundation-samples: Example content for Unity projects based on AR Foundation

We are unaware of any URP issues in 2022.3 although I do all my Android testing with Android 13.

1 Like

Also happen in 2023.2.0a18. I don’t even use Magic Leap provider in my project, only AR and XR package

Or did it needed?

Below is some errors from logcat. This was repeated nonstop. And, as mentioned in above comment, trying to switch app back and forth or switch device off/on make it work. But open it for the first time will generated these errors, like it was not initialized properly when open it up, only when it was re enabled or refocus that it could work properly

My project is trying to introduce AR into the unity’s BoatAttack sample island project

2023/06/25 16:14:46.815 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.816 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.830 26774 26774 Warn UnityMain type=1400 audit(0.0:44941): avc: denied { getattr } for name="dmabuf:" dev="dmabuf" ino=1 scontext=u:r:untrusted_app:s0:c8,c256,c512,c768 tcontext=u:object_r:unlabeled:s0 tclass=filesystem permissive=0 app=com.UnityTechnologies.BoatAttack
2023/06/25 16:14:46.839 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
2023/06/25 16:14:46.849 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.849 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.862 26774 26774 Warn UnityMain type=1400 audit(0.0:44942): avc: denied { getattr } for name="dmabuf:" dev="dmabuf" ino=1 scontext=u:r:untrusted_app:s0:c8,c256,c512,c768 tcontext=u:object_r:unlabeled:s0 tclass=filesystem permissive=0 app=com.UnityTechnologies.BoatAttack
2023/06/25 16:14:46.871 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
2023/06/25 16:14:46.882 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.882 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.894 26774 26774 Warn UnityMain type=1400 audit(0.0:44943): avc: denied { getattr } for name="dmabuf:" dev="dmabuf" ino=1 scontext=u:r:untrusted_app:s0:c8,c256,c512,c768 tcontext=u:object_r:unlabeled:s0 tclass=filesystem permissive=0 app=com.UnityTechnologies.BoatAttack
2023/06/25 16:14:46.903 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
2023/06/25 16:14:46.916 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.916 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.930 26774 26774 Warn UnityMain type=1400 audit(0.0:44944): avc: denied { getattr } for name="dmabuf:" dev="dmabuf" ino=1 scontext=u:r:untrusted_app:s0:c8,c256,c512,c768 tcontext=u:object_r:unlabeled:s0 tclass=filesystem permissive=0 app=com.UnityTechnologies.BoatAttack
2023/06/25 16:14:46.942 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
2023/06/25 16:14:46.949 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.949 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
2023/06/25 16:14:46.966 26774 26774 Warn UnityMain type=1400 audit(0.0:44945): avc: denied { getattr } for name="dmabuf:" dev="dmabuf" ino=1 scontext=u:r:untrusted_app:s0:c8,c256,c512,c768 tcontext=u:object_r:unlabeled:s0 tclass=filesystem permissive=0 app=com.UnityTechnologies.BoatAttack
2023/06/25 16:14:46.976 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)

I’m travelling and don’t have my Android test device with me now. I’ll try to get someone from our team try the AR Foundation samples.

I know that just by creating a new project in 2022 LTS from the 3D template, converting to URP, and importing the AR packages was enough to introduce the issues

I tested the AR Foundation samples in Unity 2022.3.3f1 LTS. Following the steps 2 and 3 by adding the URP package and changing the graphics pipeline did not cause the black screen to appear.

I then installed the AR Feature from the Package Manager (Step 4), which updated the AR Foundation, Apple ARKit XR plugin and Google ARCore XR plugin packages to 5.0.6, and the OpenXR plugin package to 1.8.1. This now caused the black screen issue to appear.

The device I tested with has Android 12.

This is occurring for us after updating an existing project from 2022.3.1f1 to 2022.3.3f1.
This change also updated the OpenXR plugin from 1.7.0 to 1.8.1, but reversing this change in the manifest does not resolve the issue so I suspect it is with the UnityEngine version. Google ARCore XR plugin is 5.0.6 in both versions.

There are no mentions of ARCore/Presto in the logs (i.e. ArPresto::ArPresto_initialize) which are present when things are functioning correctly, so I suspect there’s an issue initializing ARCore in this Unity version.

In our specific scenario:

  • This occurs in our in CI builds (no cache, ubuntu)
  • Local/sideload builds (windows editor) do not reproduce the issue
  • Checking/unchecking “OpenXR” from the plug-in providers in XR Plug-in Management has no effect.
  • Downgrading Unity back to 2022.3.1f1 works around the issue (keeping OpenXR plugin at 1.8.1).

设备锁屏后,再解锁,不再黑屏,是否调用 onResume 将有效??

We are investigating some issues with selecting the AR Feature in the Package Manager that sound related. This seems silly but do you see the same issues when you add the packages individually instead of selecting the AR Feature?

1 Like

I’m having a similar issue but with passthrough enabled on a Meta Quest headset.

1 Like

This is no longer occurring for me after updating to 2022.3.4f1. Much else has changed in the project, so unsure if it was only a result of the version upgrade.

Ignore that - it still occurs intermittently in 2022.3.4f1. Attempting to tell the difference between project configuration for CI runs that would cause it to work only sometimes.

@andyb-unity This issue (black screen; no XR plugin loaded at runtime) can occur on at least both iOS and Android - and appears to be the result of preloaded assets for XR not being correctly loaded/configured on my ubuntu (CI, clean) builds.

My preloaded assets looked like the following (in idle editor, not during build):
9136096--1268821--upload_2023-7-10_15-23-14.png

While configured in this way, Android builds would succeed in CI and iOS builds would not work correctly (black screen, no permissions requested). Visa-versa Android builds would not work correctly when this got ‘stuck’ with iPhone/ARKit settings.

(aside: I hadn’t noticed all the empty elements either - but presume this is due to Unity Issue Tracker - [XR] Preloaded Assets increased by 1 with each build when using Open XR Plugin and might be a leftover from an older version.)

Observations (running an ubuntu CI build on github actions)

  1. When preloaded assets are empty (in source control), ARCore is not correctly added to android builds (no session/subsystem starts) - black screen, no permissions request, but other UI works.
  2. If I manually add the relevant android settings and shaders to the editor configuration, the build works. However, if I have added the android configurations, the iOS build will exhibit the symptoms and visa versa.

The correct settings are loaded during local builds (windows editor).

Temporary workaround: use a separate branch for each platform that has different preloaded assets.


Note: this appears to be a separate issue from the thread topic… (which also does reproduce for me on the ARFoundation samples)

I have reproduced both of these issues in isolated projects from the samples and submitted issue reports:

IN-47249 - for no XR platforms included in build (black screen, no XR session)
IN-47250 - for GfxDevice Invalid State (primary post issue)

Thanks @camogram . FYI the search feature on Unity forums is not the best, so it’s easy for us to lose track of these threads to follow up.

If you wouldn’t mind taking each of these bug numbers and posting in our GitHub issues: Issues · Unity-Technologies/arfoundation-samples · GitHub, that would be the easiest way for us to follow up with you and others who may want to follow these issues as we are able to investigate them.

1 Like

Thanks, I have posted them:

2 Likes

Same here : Skipped rendering frame because GfxDevice is in invalid state (device lost). Black screen. Android App do not start.

The problem is in the AR package collection. Doesn`t matter if project is on Universal RP.

This one works, thanks. The ARCore need to be installed alone (it will install all required dependencies).

Issue confirmed and resolved on Unity 2022.3.5, Windows 10, tested on Samsung Galaxy S9. ARFoundation 5.0.6 (problem also exist on 5.1.0-pre9).

2 Likes

@Lib_one Thanks for letting us know. I see that @camogram included the same information in their bug report. QA team is currently reviewing this issue.

I have the same issue, one quick and trick solution is if you get the black screen then lock and unlock the screen, the app should work.

2 Likes