google-ar / arcore-android-sdk

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

ACameraManager: openCamera: connect camera device failed: Status(-8): '8: connectHelper:1305: Cannot open camera 0 for "" (PID -1): Too many other clients connecting' #405

Closed Nullifier1571 closed 6 years ago

Nullifier1571 commented 6 years ago

i use the sample code and modify as this issue https://github.com/google-ar/arcore-android-sdk/issues/110#issuecomment-384096267 .its worked when first installed.but when i restart my app,the camera always twinkle .even i unstall it or restart device it cant be normal ! it`s also happend in emulator,i must delate emulator and recreate emulator.

this is the log: 05-31 11:53:06.747 5428-5428/com.google.ar.core.examples.java.helloar E/NdkImageReader: AImageReader_getWindow 05-31 11:53:09.764 5428-5428/com.google.ar.core.examples.java.helloar E/ACameraManager: openCamera: connect camera device failed: Status(-8): '8: connectHelper:1305: Cannot open camera 0 for "" (PID -1): Too many other clients connecting' 05-31 11:53:09.765 5428-5428/com.google.ar.core.examples.java.helloar E/native: android_camera.cc:624 Reset: Resetting camera 0 from an ERROR state, best effort clean-up commencing 05-31 11:53:09.769 5428-5428/com.google.ar.core.examples.java.helloar E/native: status.cc:158 ArStatusErrorSpace::AR_ERROR_CAMERA_NOT_AVAILABLE: 05-31 11:55:15.769 5428-5428/com.google.ar.core.examples.java.helloar E/bbd: ~~~ Channel {0} was not shutdown properly!!! ~~~ Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true. java.lang.RuntimeException: ManagedChannel allocation site at bbe.(PG:4) at bbd.(PG:4) at bbd.(PG:1) at aui.a(PG:63) at com.google.ar.persistence.AnchorServiceClientFactory.create(PG:17) at com.google.ar.core.Session.nativeCreateSession(Native Method) at com.google.ar.core.Session.(Unknown Source:22) at com.google.ar.core.examples.java.helloar.HelloArActivity.onResume(HelloArActivity.java:148) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355) at android.app.Activity.performResume(Activity.java:7117) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 05-31 11:55:15.770 5428-5428/com.google.ar.core.examples.java.helloar E/bbd: ~~~ Channel {0} was not shutdown properly!!! ~~~ Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true. java.lang.RuntimeException: ManagedChannel allocation site at bbe.(PG:4) at bbd.(PG:4) at bbd.(PG:1) at aui.a(PG:63) at com.google.ar.persistence.AnchorServiceClientFactory.create(PG:18) at com.google.ar.core.Session.nativeCreateSession(Native Method) at com.google.ar.core.Session.(Unknown Source:22) at com.google.ar.core.examples.java.helloar.HelloArActivity.onResume(HelloArActivity.java:148) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355) at android.app.Activity.performResume(Activity.java:7117) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 05-31 11:55:15.795 5428-5428/com.google.ar.core.examples.java.helloar E/NdkImageReader: AImageReader_getWindow 05-31 11:55:18.800 5428-5428/com.google.ar.core.examples.java.helloar E/ACameraManager: openCamera: connect camera device failed: Status(-8): '8: connectHelper:1305: Cannot open camera 0 for "" (PID -1): Too many other clients connecting' 05-31 11:55:18.800 5428-5428/com.google.ar.core.examples.java.helloar E/native: android_camera.cc:624 Reset: Resetting camera 0 from an ERROR state, best effort clean-up commencing 05-31 11:55:18.805 5428-5428/com.google.ar.core.examples.java.helloar E/native: status.cc:158 ArStatusErrorSpace::AR_ERROR_CAMERA_NOT_AVAILABLE:

and this is my code

` @Override public void onDrawFrame(GL10 gl) { // Clear screen to notify driver it should not load any pixels from previous frame. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (session == null) {
        return;
    }
    // Notify ARCore session that the view size changed so that the perspective matrix and
    // the video background can be properly adjusted.
    displayRotationHelper.updateSessionIfNeeded(session);

    try {
        session.setCameraTextureName(backgroundRenderer.getTextureId());

        // Obtain the current frame from ARSession. When the configuration is set to
        // UpdateMode.BLOCKING (it is by default), this will throttle the rendering to the
        // camera framerate.
        Frame frame = session.update();
        Camera camera = frame.getCamera();
        // Handle taps. Handling only one tap per frame, as taps are usually low frequency
        // compared to frame rate.
        MotionEvent tap = tapHelper.poll();
        if (tap != null && camera.getTrackingState() == TrackingState.TRACKING) {
            for (HitResult hit : frame.hitTest(tap)) {
                // Check if any plane was hit, and if it was hit inside the plane polygon
                Trackable trackable = hit.getTrackable();
                // Creates an anchor if a plane or an oriented point was hit.
                if ((trackable instanceof Plane
                        && ((Plane) trackable).isPoseInPolygon(hit.getHitPose())
                        && (PlaneRenderer.calculateDistanceToPlane(hit.getHitPose(), camera.getPose())
                        > 0))
                        || (trackable instanceof Point
                        && ((Point) trackable).getOrientationMode()
                        == OrientationMode.ESTIMATED_SURFACE_NORMAL)) {
                    // Hits are sorted by depth. Consider only closest hit on a plane or oriented point.
                    // Cap the number of objects created. This avoids overloading both the
                    // rendering system and ARCore.
                    if (anchors.size() >= 2) {
                        anchors.get(0).detach();
                        anchors.remove(0);
                    }
                    // Adding an Anchor tells ARCore that it should track this position in
                    // space. This anchor is created on the Plane to place the 3D model
                    // in the correct position relative both to the world and to the plane.
                    anchors.add(hit.createAnchor());
                    break;
                }
            }
        }

        **if (!isLock) {
            anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0, 0, -1f))
                            .extractTranslation()));

            anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(-0.5f, 0, -1f))
                            .extractTranslation()));

            anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0.5f, 0, -1f))
                            .extractTranslation()));

            /*anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0.f, 0, 1f))
                            .extractTranslation()));*/

            /*anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0, 0.5f, -1f))
                            .extractTranslation()));

            anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0, -0.5f, -1f))
                            .extractTranslation()));*/
            isLock = true;
        }**

        // Draw background.
        backgroundRenderer.draw(frame);

        // If not tracking, don't draw 3d objects.
        if (camera.getTrackingState() == TrackingState.PAUSED) {
            return;
        }

        // Get projection matrix.
        camera.getProjectionMatrix(projmtx, 0, 0.1f, 100.0f);

        // Get camera matrix and draw.
        camera.getViewMatrix(viewmtx, 0);

        // Compute lighting from average intensity of the image.
        // The first three components are color scaling factors.
        // The last one is the average pixel intensity in gamma space.
        final float[] colorCorrectionRgba = new float[4];
        frame.getLightEstimate().getColorCorrection(colorCorrectionRgba, 0);

        // Visualize tracked points.
        PointCloud pointCloud = frame.acquirePointCloud();
        pointCloudRenderer.update(pointCloud);
        pointCloudRenderer.draw(viewmtx, projmtx);

        // Application is responsible for releasing the point cloud resources after
        // using it.
        pointCloud.release();

        // Check if we detected at least one plane. If so, hide the loading message.
        if (messageSnackbarHelper.isShowing()) {
            for (Plane plane : session.getAllTrackables(Plane.class)) {
                if (plane.getType() == com.google.ar.core.Plane.Type.HORIZONTAL_UPWARD_FACING
                        && plane.getTrackingState() == TrackingState.TRACKING) {
                    messageSnackbarHelper.hide(this);
                    break;
                }
            }
        }

        // Visualize planes.
        planeRenderer.drawPlanes(
                session.getAllTrackables(Plane.class), camera.getDisplayOrientedPose(), projmtx);

        // Visualize anchors created by touch.
        float scaleFactor = 1.0f;
        for (Anchor anchor : anchors) {
            if (anchor.getTrackingState() != TrackingState.TRACKING) {
                continue;
            }
            // Get the current pose of an Anchor in world space. The Anchor pose is updated
            // during calls to session.update() as ARCore refines its estimate of the world.
            anchor.getPose().toMatrix(anchorMatrix, 0);

            // Update and draw the model and its shadow.
            virtualObject.updateModelMatrix(anchorMatrix, scaleFactor);
            virtualObjectShadow.updateModelMatrix(anchorMatrix, scaleFactor);
            virtualObject.draw(viewmtx, projmtx, colorCorrectionRgba);
            virtualObjectShadow.draw(viewmtx, projmtx, colorCorrectionRgba);
        }

    } catch (Throwable t) {
        // Avoid crashing the application due to unhandled exceptions.
        Log.e(TAG, "Exception on the OpenGL thread", t);
    }
}`
Nullifier1571 commented 6 years ago

if (!isLock) { anchors.add(session.createAnchor( frame.getCamera().getDisplayOrientedPose() .compose(Pose.makeTranslation(0, 0.5f, -1f)) .extractTranslation()));

            anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0, -0.5f, -1f))
                            .extractTranslation()));
            isLock = true;
        }

even i delate my modify it also can`t be normal

inio commented 6 years ago

That's confusing. Is it possible you're creating a second Session object or something?

Nullifier1571 commented 6 years ago

i really don't know what's wrong.it's this code will create a new session?

anchors.add(session.createAnchor(
                    frame.getCamera().getDisplayOrientedPose()
                            .compose(Pose.makeTranslation(0, -0.5f, -1f))
                            .extractTranslation()));
inio commented 6 years ago

Nope, that's just creating an anchor. This problem would be up in onResume most likely.

inio commented 6 years ago

Closing for inactivity.