google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.95k stars 1.22k forks source link

ArSession_update fails after pause/resume, even with session re-creation #1309

Open robbiesri opened 2 years ago

robbiesri commented 2 years ago

SPECIFIC ISSUE ENCOUNTERED

We've been getting reports about UE4 hitting failures after pause/resume with ARCore. After pause/resuming 2/3 times, I can see that we can't get an updated camera feed.

After initial debugging of the issue, I found that ArSession_update was returning AR_ERROR_FATAL (ArSession_update docs). At this point, my assumption is that the session is hosed, and the only thing I can do is tear down this session, and create a new session.

I can successfully destroy the old session, and create a new sesson. I chug along until I get back to ArSession_update and...it fails in the exact same way.

I tried to recreate the issue in the SDK samples. I couldn't get the session to fail with pause/resume.

VERSIONS USED

STEPS TO REPRODUCE THE ISSUE

  1. Create sample project from UE4 handheld AR template (reproduces on UE 4.27, reported on UE 4.24+ with different ARCore SDKs + Android versions)
  2. Package and launch the app on a ARCore device
  3. Switch between the deployed app and another app a couple times. Eventually, the camera will stop working.

ADDITIONAL COMMENTS

devbridie commented 2 years ago

Hi Rob, would be great if you could package a sample; please send it to dereckbridie@google.com. If the UE4 AR template is OSS, could you tell me where I could find that as well?

robbiesri commented 2 years ago

Thanks for the quick response, Dereck!

Here is the template soure: https://github.com/EpicGames/UnrealEngine/tree/4.27/Templates/TP_AEC_HandheldARBP But you'd just sync the repo, build the engine, and then create a new project based on the Handheld AR template.

I'll package up a debug and development build to send to you right meow

devbridie commented 2 years ago

Repro'd in the sample you sent; that's strange. It seems that the session update is being called on a thread that isn't EGL compatible. Will try to look into this, but I'm not an expert on this platform.

robbiesri commented 2 years ago

Hey Dereck, thanks for the word. I think that makes sense, since we call update on the game thread, which typically doesn't have access to the GL context. That being said, I'm surprised that it hasn't fallen over previously. I don't see an explicit requirement that the GL context is accessible in a particular thread, but I do see that ArSession_update can return an error about a missing GL context (AR_ERROR_MISSING_GL_CONTEXT), which implies the GL context is accessible on the thread that calls ArSession_update.

Edit: actually, I need to be more sure about which threads do or do not have access to the GL context. I could be incorrect my assumption.

CanYouEatIt commented 5 days ago

Was there any fix for this?