A clear and concise description of what the bug is.
App is crashing everytime when trying to capture an image on Android version 6.0.1.
This is how I initialized CameraView
mCameraView.setLifecycleOwner((LifecycleOwner) mActivity);
mCameraView.setSessionType(SessionType.PICTURE);
mCameraView.setFacing(Facing.BACK); //back camera
mCameraView.setJpegQuality(100);
mCameraView.setPlaySounds(true);
mCameraView.setCropOutput(true);
mCameraView.addCameraListener(new MyCameraListener());
mCameraView.addFrameProcessor(new MyFrameProcessor());
Calling CameraView.capturePicture(); is causing the crash.
Steps to reproduce the behavior, possibly in the demo app:
Should receive image bitmap in the listener.
If applicable, add screenshots to help explain your problem.
--------------------Moto G Logs-------------------
Throwing OutOfMemoryError "Failed to allocate a 38937612 byte allocation with 16773536 free bytes and 22MB until OOM"
01-10 14:03:41.109 30373-30505/com.expenseondemand.smartscan E/AndroidRuntime: FATAL EXCEPTION: CameraViewWorker
Process: com.expenseondemand.smartscan, PID: 30373
java.lang.OutOfMemoryError: Failed to allocate a 38937612 byte allocation with 16773536 free bytes and 22MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:857)
at android.graphics.Bitmap.createBitmap(Bitmap.java:834)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.graphics.Bitmap.createBitmap(Bitmap.java:679)
at com.otaliastudios.cameraview.CropHelper.cropToJpeg(CropHelper.java:26)
at com.otaliastudios.cameraview.CameraView$Callbacks$4.run(CameraView.java:1590)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-10 14:03:41.162 30373-30373/com.expenseondemand.smartscan I/CameraController: Stop: posting runnable. State: STATE_STARTED
01-10 14:03:41.163 30373-30503/com.expenseondemand.smartscan I/CameraController: Stop: executing. State: STATE_STARTED
01-10 14:03:41.163 30373-30503/com.expenseondemand.smartscan I/CameraController: Stop: about to call onStop()
01-10 14:03:41.164 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: About to clean up.
01-10 14:03:41.174 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: Clean up. Ending video.
01-10 14:03:41.174 30373-30503/com.expenseondemand.smartscan I/Camera1: endVideoImmediately: is capturing: false
01-10 14:03:41.175 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: Clean up. Stopping preview.
01-10 14:03:41.299 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: Clean up. Stopped preview.
01-10 14:03:41.299 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: Clean up. Releasing camera.
01-10 14:03:41.344 30373-30503/com.expenseondemand.smartscan I/Camera1: onStop: Clean up. Released camera.
01-10 14:03:41.344 30373-30503/com.expenseondemand.smartscan W/Camera1: onStop: Clean up. Returning.
01-10 14:03:41.345 30373-30503/com.expenseondemand.smartscan I/CameraController: Stop: returned from onStop(). Dispatching.
01-10 14:03:41.345 30373-30503/com.expenseondemand.smartscan I/CameraCallbacks: dispatchOnCameraClosed
----------------------Oneplus X logs ---------------------
Throwing OutOfMemoryError "Failed to allocate a 38937612 byte allocation with 16777216 free bytes and 30MB until OOM"
01-10 14:22:01.732 931-956/com.expenseondemand.smartscan E/AndroidRuntime: FATAL EXCEPTION: CameraViewWorker
Process: com.expenseondemand.smartscan, PID: 931
java.lang.OutOfMemoryError: Failed to allocate a 38937612 byte allocation with 16777216 free bytes and 30MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:857)
at android.graphics.Bitmap.createBitmap(Bitmap.java:834)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.graphics.Bitmap.createBitmap(Bitmap.java:679)
at com.otaliastudios.cameraview.CropHelper.cropToJpeg(CropHelper.java:26)
at com.otaliastudios.cameraview.CameraView$Callbacks$4.run(CameraView.java:1590)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Link to a Github repo where the bug is reproducible.
Below is the root cause of this issue.
CameraView.setCropOutput(false);
Turning this to false fixed the issue on all devices. I faced this with two other Samsung devices running android 7.0.
Yes, please remove cropOutput or update to v2.
Most helpful comment
Below is the root cause of this issue.
CameraView.setCropOutput(false);
Turning this to false fixed the issue on all devices. I faced this with two other Samsung devices running android 7.0.