Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: setParameters failed #27

Open
aryaonong29 opened this issue Apr 20, 2018 · 1 comment
Open

java.lang.RuntimeException: setParameters failed #27

aryaonong29 opened this issue Apr 20, 2018 · 1 comment

Comments

@aryaonong29
Copy link

To Everyone who's facing this problem :

Process: com.androidluckyguys, PID: 6480
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:2034)
at com.androidluckyguys.ARCamera.surfaceChanged(ARCamera.java:215)
at android.view.SurfaceView.updateWindow(SurfaceView.java:634)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:161)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2265)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1286)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6536)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

I solved the problem when the preview camera doesn't show up and being force closed.

I tried with high end LG devices and debug the ARCamera code to verify some values related to dimension supported.

I start with finding the preview value for width and height from surfaceChanged() :

       this.cameraWidth = width;
           this.cameraHeight = height;

           Camera.Parameters params = camera.getParameters();
           params.setPreviewSize(previewSize.width, previewSize.height);
           requestLayout();

           camera.setParameters(params);
           camera.startPreview();

           generateProjectionMatrix();

I got the supplied value was 1440 for width and 2072 for height. And this is the problem, the dimension supplied was too big and
not supported by the device itself. So I compared with the received value in supportPreviewSizes and I got :

SupportedPreviewSizes : size = 16

with this values :

1920x1080
1600x1200
1280x960
1280x768
1280x720
1024x768
......... and soon

So it proved that the index 0 of the supportedPreviewSizes is smaller than supplied value in this line
params.setPreviewSize(previewSize.width, previewSize.height);

The solution was easy : I changed the supplied value from the index 0 of supportedPreviewSizes so the line will be
params.setPreviewSize(supportedPreviewSizes.get(0).width,
supportedPreviewSizes.get(0).height);

and overall method will be like this

@UiThread
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(camera != null) {
if (!supportedPreviewSizes.isEmpty()){
this.cameraWidth = width;
this.cameraHeight = height;

           Camera.Parameters params = camera.getParameters();
           params.setPreviewSize(supportedPreviewSizes.get(0).width,
                   supportedPreviewSizes.get(0).height);
           requestLayout();

           camera.setParameters(params);
           camera.startPreview();

           generateProjectionMatrix();
       }
    }
}          
@Navi91
Copy link

Navi91 commented Sep 11, 2018

Change method setCamera implementation to:

`public void setCamera(Camera camera) {
this.camera = camera;

    if (this.camera != null) {
        Camera.Parameters params = this.camera.getParameters();

        List<String> focusModes = params.getSupportedFocusModes();
        if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
            params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            this.camera.setParameters(params);
        }

        supportedPreviewSizes = this.camera.getParameters().getSupportedPreviewSizes();
        requestLayout();
    }
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants