Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'AR' started by teemu_immersal, Jun 15, 2023.

  1. teemu_immersal

    teemu_immersal

    Joined:
    Aug 22, 2017
    Posts:
    4
    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:
    1. Create a new project in Unity 2022.3.2f1 (or any other LTS version) with the 3D template
    2. Install the Universal RP package through Package Manager
    3. Create the Universal Render Pipeline Asset and Renderer and add the ARBackgroundRendererFeature
    4. Install the AR package collection (5 in total) through Package Manager
    5. Add the AR Session and XR Origin (Mobile AR) setup to the default SampleScene and remember to delete MainCamera
    6. Remove Vulkan from Graphics API, set Minimum API Level to 24, change Target Architecture to ARM64
    7. 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:
    1. Remove all AR packages
    2. Close Unity, delete Library,
    3. Install only Google ARCore XR Plugin
    4. Build for Android

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

    Attached Files:

    TheBraxo likes this.
  2. teemu_immersal

    teemu_immersal

    Joined:
    Aug 22, 2017
    Posts:
    4
    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.
     
  3. teemu_immersal

    teemu_immersal

    Joined:
    Aug 22, 2017
    Posts:
    4
    andyb-unity likes this.
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    teemu_immersal likes this.
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,133
    Also happen in 2023.2.0a18. I don't even use Magic Leap provider in my project, only AR and XR package

    upload_2023-6-25_16-8-48.png

    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

    Code (CSharp):
    1. 2023/06/25 16:14:46.815 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
    2. 2023/06/25 16:14:46.816 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
    3. 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
    4. 2023/06/25 16:14:46.839 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
    5. 2023/06/25 16:14:46.849 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
    6. 2023/06/25 16:14:46.849 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
    7. 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
    8. 2023/06/25 16:14:46.871 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
    9. 2023/06/25 16:14:46.882 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
    10. 2023/06/25 16:14:46.882 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
    11. 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
    12. 2023/06/25 16:14:46.903 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
    13. 2023/06/25 16:14:46.916 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
    14. 2023/06/25 16:14:46.916 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
    15. 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
    16. 2023/06/25 16:14:46.942 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
    17. 2023/06/25 16:14:46.949 26774 26839 Error libEGL eglPresentationTimeANDROIDImpl:2221 error 300d (EGL_BAD_SURFACE)
    18. 2023/06/25 16:14:46.949 26774 26839 Error libEGL eglSwapBuffersWithDamageKHRImpl:1352 error 300d (EGL_BAD_SURFACE)
    19. 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
    20. 2023/06/25 16:14:46.976 26774 26798 Info Unity Skipped rendering frame because GfxDevice is in invalid state (device lost)
     
  6. teemu_immersal

    teemu_immersal

    Joined:
    Aug 22, 2017
    Posts:
    4
    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
     
  7. jesse-immersal

    jesse-immersal

    Joined:
    May 16, 2023
    Posts:
    1
    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.
     
  8. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    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).
     
  9. Game-ToGo

    Game-ToGo

    Joined:
    Dec 12, 2018
    Posts:
    1
    设备锁屏后,再解锁,不再黑屏,是否调用 onResume 将有效??
     
  10. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    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?
     
  11. Yearwood

    Yearwood

    Joined:
    Jul 31, 2018
    Posts:
    9
    I'm having a similar issue but with passthrough enabled on a Meta Quest headset.
     
  12. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    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.
     
  13. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    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.
     
  14. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    @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):
    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 https://issuetracker.unity3d.com/is...y-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)
     
    Last edited: Jul 11, 2023
  15. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    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)
     
  16. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    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: https://github.com/Unity-Technologies/arfoundation-samples/issues, 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.
     
  17. camogram

    camogram

    Joined:
    Jul 11, 2018
    Posts:
    23
    Thanks, I have posted them:
    - https://github.com/Unity-Technologies/arfoundation-samples/issues/1090
    - https://github.com/Unity-Technologies/arfoundation-samples/issues/1091
     
    teemu_immersal and andyb-unity like this.
  18. Lib_one

    Lib_one

    Joined:
    Mar 26, 2018
    Posts:
    2
    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).
     
  19. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    @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.
     
  20. WeiWuDe

    WeiWuDe

    Joined:
    Nov 3, 2020
    Posts:
    26
    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.
     
    AldeRoberge and rlegiedz like this.
  21. rlegiedz

    rlegiedz

    Joined:
    Nov 13, 2016
    Posts:
    3
    Thanks for that, works like a charm - at least while developing.. ;-)
     
  22. madhuavunuri

    madhuavunuri

    Joined:
    Sep 4, 2014
    Posts:
    3
    I am having the same issue with Unity 2022.3.10 and @WeiWuDe Thanks for the trick its helped to continue to test
     
  23. melitoren

    melitoren

    Joined:
    May 13, 2020
    Posts:
    5
    Same problem unity 2022.3.11 Samsung tab 7 FE
     
  24. melitoren

    melitoren

    Joined:
    May 13, 2020
    Posts:
    5
    updated to unity 2022.3.12 problem still happens
     
  25. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    283
    I am having the same issue with Unity 2022.3.11
     
  26. wilcoboode

    wilcoboode

    Joined:
    Nov 16, 2012
    Posts:
    6
    I have this issue with the Quest 3 and Unity Meta OpenXR plugin
    Unity 2022.3.12f1, Meta OpenXR 1.0.0, OpenXR 1.8.2, XR Interaction Toolkit 2.5.2
    "Skipped rendering frame because GfxDevice is in invalid state (device lost)"

    The application does work as expected after locking and unlocking the device. But its very annoying that we need to do this everytime we launch the app!
     
  27. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    We have someone looking into this issue now. It appears to be specific to certain Android devices. If you all could share the device(s) on which you observe this issue, that might help us out.
     
    Last edited: Dec 1, 2023
  28. storylab_aru

    storylab_aru

    Joined:
    Dec 6, 2022
    Posts:
    1
    Experiencing the same issue. The black screen will go away after rotating the device, or locking and unlocking the device, and the app will then behave normally. Of note is that even the Unity splashscreen on loading the app is blacked out.

    Sony Xperia 5 IV
    Android 13
    Unity 2022.3.5f1
    Built-in RP
    AR Foundation 5.0.7
     
  29. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    283
    Unity 2022.3.6f1
    AR Foundation 5.0.6
    ----------------------------------------------
    ROG Phone 5
    Android 13 (API Level 33)
    Buid No: WW_33.0120.0210.235

    Xperia 5 II SOG02
    Android 10 (API Level 24)

    Nubia Pad 3D LPD-20W
    Android 12 (API Level 30)
    Buid No LPD-20WV1.0.0B07_EEA

    Xperia Sphinx (J8010)
    Android 9 (API Level 28)
    ==========================


    I've tried it on 4 devices I have and the same problem occurs on all.
    Is this really a phenomenon that only occurs on some devices?
    Based on the verification results, this problem appears to occur on almost all devices.
     
  30. GeorgeMincila

    GeorgeMincila

    Joined:
    Feb 28, 2016
    Posts:
    36
    Has anyone succeeded in a fix for this?

    I am running into the same black screen on start. I can use the device power button twice to start seeing the actual view, but this is not something that can be published.
    I am testing on a Samsung Galaxy A6, Unity 2022.3.14f1, ARCore package 5.1.1, AR Foundation 5.1.1, ARKit 5.1.1
     
  31. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    Do you have the AR Feature enabled in Package Manager? If so, please remove this feature and make sure that the Magic Leap package is removed from your project.
     
  32. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    283
    AR was enabled and the Magic Leap package was added to the project, so I disabled AR, confirmed that the Magic Leap package was removed, and tried building and running again, but the symptoms remained the same. , a black screen appears.
     
  33. GeorgeMincila

    GeorgeMincila

    Joined:
    Feb 28, 2016
    Posts:
    36
    I do not have the AR Feature enabled. (or any other) in Package Manager. I have the packages installed (Packages section). My project is coming from an older Unity version and upgraded. It is not a new one.
    I found that I had the Magic Leap XR Plugin installed from the Package Manager - > I Removed it.

    The result is the same: black screen on launch.

    -------
    Later Edit: There is another action suggested here in this thread. I have done this after what I have written above and that did solve it.
    The action I am referring to is: Close Unity & Unity Hub. Delete the Library folder from project. Open Unity again, select Android, Build & Run.
     
    Last edited: Dec 12, 2023
  34. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    283
    Oh, This solution resolved me too.
     
  35. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
    Thanks. Looks like it's a two-step workaround for this issue:

    * Remove Magic Leap plug-in from your project
    * Close Unity and delete Library

    I've sent your reports to our QA team, and we should have enough info to pass to our Magic Leap devs to work on a fix.
     
    GeorgeMincila and AldeRoberge like this.
  36. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    198
    @camogram Does removing the Magic Leap package resolve the issue you were seeing with your CI?
     
  37. Blynk_William

    Blynk_William

    Joined:
    Nov 3, 2022
    Posts:
    1
    Adding my discoveries: I experience this issue with both Samsung tablets (Tab A8 and Tab S8 Ultra) that we have, but not my Pixel 6 (works fine on that phone) - which is in line with other people's mentions above - so maybe a OneUI related issue??. Currently using Unity 2022.3.16f1 on ARFoundation 5.1.1

    Whilst developing you can (when the build is complete and you see a black screen) go to the Android home page and then open the app again with the recent app switcher - this fixes the problem for development purposes (obvs not production)
     
    Last edited: Jan 18, 2024
  38. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    956
  39. briotto-sfl

    briotto-sfl

    Joined:
    Nov 5, 2021
    Posts:
    2
    @andyb-unity Am I correct in understanding that it is currently not (easily) feasible to build for Quest 3 and Magic Leap 2 from the same project since I will need to remove Magic Leap packages every time I want to build for Quest? Are there any updates on a potential fix for this?
     
  40. Sashell_

    Sashell_

    Joined:
    Jul 14, 2021
    Posts:
    17
    I am in the exact same position as you are. MagicLeap recently added OpenXR support (https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/openxr-unity-overview/) in Unity, which would mean no MLXRPlugin to install.

    I am trying to make this kind of corss platform project work, please keep me updated if you find anything