com.google.ar.core.exceptions.NotYetAvailableException on frame.acquireCameraImage()

Viewed 469

Case 1: This is the code

private void onUpdateListener(FrameTime frameTime) {
    try
    {
        Frame frame = nodeArFragment.getArSceneView().getArFrame();

        if (frame == null) {
            return;
        }

        computingDetection = true;


        Image androidMediaImage = frame.acquireCameraImage();

        Bitmap rotatedImage = Utilities.getBitmap(androidMediaImage,detector);
        imageView.setImageBitmap(rotatedImage);

        new Thread(() -> {
            List<Classifier.Recognition> results = null;

              results = detector.recognizeImage(rotatedImage);

      //  drawBoxes(results);
        }).start();

    } catch (NotYetAvailableException e) {
        Log.e(TAG, "NotYetAvailableException", e);
        e.printStackTrace();
    } catch (DeadlineExceededException e){
        Log.e(TAG, "DeadlineExceededException", e);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

When this is the code, I'm getting this error

FAILED_PRECONDITION: 
    ARCoreError: third_party/arcore/ar/core/cpu_image_manager.cc:252
     [type.googleapis.com/util.ErrorSpacePayload='ArStatusErrorSpace::AR_ERROR_NOT_YET_AVAILABLE']
2020-11-21 06:53:23.389 24361-24361/com.example.nodetypesarcore E/ContentValues: NotYetAvailableException
    com.google.ar.core.exceptions.NotYetAvailableException
        at java.lang.reflect.Constructor.newInstance0(Native Method)

Case 2: When I removed the thread, I get the error for the first frame, but it doesn't stop the application and continues to work from the next frame! But in the previous case, the application stops on receiving that error!

    try
    {
        Frame frame = nodeArFragment.getArSceneView().getArFrame();

        if (frame == null) {
            return;
        }

        computingDetection = true;


        Image androidMediaImage = frame.acquireCameraImage();

        Bitmap rotatedImage = Utilities.getBitmap(androidMediaImage,detector);
        imageView.setImageBitmap(rotatedImage);

        List<Classifier.Recognition> results = null;

        results = detector.recognizeImage(rotatedImage);

     
    } catch (NotYetAvailableException e) {
        Log.e(TAG, "NotYetAvailableException", e);
        e.printStackTrace();
    } catch (DeadlineExceededException e){
        Log.e(TAG, "DeadlineExceededException", e);
    } catch (Exception e) {
        e.printStackTrace();
    }

But if I remove the thread, it's very laggy but it works as expected. So how do I have a thread and avoid the error? Thank you!

0 Answers
Related