google-ar / arcore-android-sdk

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

Frame frame = session.update() throws AR_ERROR_SESSION_PAUSED #706

Closed patrick-ucr closed 5 years ago

patrick-ucr commented 5 years ago

SPECIFIC ISSUE ENCOUNTERED

I am adding some ARCore functionalities to Tensorflow for Android's DetectorActivity. When I need access to the camera using this code (with related codes from AugmentedImageActivity.java sample code) Frame frame = session.update(); Camera camera = frame.getCamera(); I get exception

ArStatusErrorSpace::AR_ERROR_SESSION_PAUSED: Could not update frame, session is paused

I checked and found that CameraPermissionHelper.requestCameraPermission(this) has failed mainly because DetectorActivity extending CameraActivity is already granted Camera permission.

My question is that how I can link android.hardward.Camera to com.google.ar.core.Camera so that the ARCore session can run without the above exception.

VERSIONS USED

fredsa commented 5 years ago

The permission and other Android manifest requirements are documented here:

https://developers.google.com/ar/develop/java/enable-arcore

abhishekk06 commented 3 years ago

Hi,

I am facing the similar issue. I do have all the required configurations done to enable ARCore. Can somebody help me understand what went wrong?

`2021-03-04 23:00:55.148 8885-8885/com.android.example.camerax.tflite E/native: error_policy_util.cc:263 ################ ARCore Native Error ################## BUILD_CHANGELIST:356413513 BUILD_BASELINE_CHANGELIST:353781137 ################### Stack Trace Begin ################ ARCoreError: third_party/arcore/ar/core/session.cc:1670 https://cs.corp.google.com/piper///depot/google3/third_party/arcore/ar/core/session.cc?g=0&l=1670 ARCoreError: third_party/arcore/ar/core/c_api/session_lite_c_api.cc:75 https://cs.corp.google.com/piper///depot/google3/third_party/arcore/ar/core/c_api/session_lite_c_api.cc?g=0&l=75 ################### Stack Trace End #################

################### Undecorated Trace Begin  #################
FAILED_PRECONDITION: 
ARCoreError: third_party/arcore/ar/core/session.cc:1670
 at third_party/arcore/ar/core/session.cc:1672Cannot update frame, session is paused. [type.googleapis.com/util.ErrorSpacePayload='ArStatusErrorSpace::AR_ERROR_SESSION_PAUSED']
################### Undecorated Trace End  #################

2021-03-04 23:00:55.155 8885-8885/com.android.example.camerax.tflite D/AndroidRuntime: Shutting down VM 2021-03-04 23:00:55.159 8885-8885/com.android.example.camerax.tflite E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.example.camerax.tflite, PID: 8885 com.google.ar.core.exceptions.SessionPausedException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.google.ar.core.Session.throwExceptionFromArStatus(Session.java:16) at com.google.ar.core.Session.nativeUpdate(Native Method) at com.google.ar.core.Session.update(Session.java:2) at com.android.example.camerax.tflite.CameraActivity.onDrawFrame(CameraActivity.kt:355) at com.android.example.camerax.tflite.CameraActivity$reportPrediction$1.run(CameraActivity.kt:234) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:8167) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 2021-03-04 23:00:55.250 8885-8885/com.android.example.camerax.tflite I/Process: Sending signal. PID: 8885 SIG: 9`

devbridie commented 3 years ago

@abhishekk06, this error occurs when Session.update is called before Session.resume is called. If your code is open source, I wouldn't mind having a look if you can share it.

abhishekk06 commented 3 years ago

Yes. Please have a look.

https://github.com/abhishekk06/sandbox

Also please note that I am fairly new to android development and I was following the steps given in the developer guide to integrating ARcore into the existing app.

devbridie commented 3 years ago

No problem! I think the following is going on:

session.resume() is called in reportPrediction which is in a lambda to imageAnalysis.setAnalyzer. This means that each analysis will trigger session.resume(); however, session.resume should only be called once, typically through the Activity lifecycle. Check out how it's done in Hello AR Java.

abhishekk06 commented 3 years ago

Hi @devbridie ,

I tried pulling session.resume() to configure the session so that it can be called only once during on create. But for some reason, it just gives a black screen after that. Is there anything I am missing in your explanation. Will it be possible to have short sync?

abhishekk06 commented 3 years ago

Hi @devbridie,

I updated my repo with the session.resume() being pulled to onStart() and onResume(). Can you please review it and let me know if in case I am doing something wrong.

Thanks a lot for your help. :)