Glide crashes with beta10, beta11

275 views
Skip to first unread message

Alexander Popov

unread,
Nov 3, 2020, 5:09:03 AM11/3/20
to Android CameraX Discussion Group
Hello, CameraX Development Team!

I’m using CameraX ImageCapture to save a photo and Glide 4.11.0 to load the saved image.

Recently I’ve noticed that my application starts crashing when I try to take a photo and load it multiple times by calling ImageCapture really quickly.

I got this issue when I updated camera-core to beta10 and camera-view to alpha17. I checked beta11 and alpha18 and got exactly the same result. Only after I went back to beta08 and alpha15 this issue disappeared.

You can find a crash log and my code snippets in the attachment
save_image_code.txt
log.txt
load_image_code.txt

Leo Huang

unread,
Nov 3, 2020, 11:00:16 PM11/3/20
to Android CameraX Discussion Group, ale...@nsysgroup.com
Hi,
Thanks for reporting this problem and attaching the log and code.

From the attached log,

    W/Glide: Load failed for /storage/emulated/0/Android/data/photoset/76fc72_fr.jpg with size [-2147483648x-2147483648]

seem to indicate a size problem.

I also see the source code to crop and override the EXIF.

try {
    ExifInterface exifInterface = new ExifInterface(photoFile.getAbsolutePath());
    ExifData exifData = loadExifData(exifInterface);
    photoSet.setExifData(exifData);
    cropAndCompressPhotoFile(photoFile);
    exifInterface.saveAttributes();
} catch (IOException e) { e.printStackTrace(); }


I am wondering what will cropAndCompressPhotoFile do?
We are still investigating the issue. In the mean time, could you also try to remove above EXIF overriding to see if the problem still exist?
That's can help to narrow down the possible root cause.
Thanks

ale...@nsysgroup.com 在 2020年11月3日 星期二下午6:09:03 [UTC+8] 的信中寫道:

Alexander Popov

unread,
Nov 5, 2020, 3:10:55 AM11/5/20
to Android CameraX Discussion Group, leoh...@google.com, Alexander Popov
The cropAndCompressPhotoFile method crops, rescales and saves a photo with compression.

I tried to delete this method and got this problem with less reproducibility (about 2 of 15, it was 10 of 10 before).
After I deleted EXIF overriding lines too the problem probably disappeared, I tried about 20 times.

Here is my cropAndCompressPhotoFile method code:

 private void cropAndCompressPhotoFile(File photoFile) throws IOException {
        try {
            Bitmap photoBitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath());

            if (photoBitmap != null) {
                int sourceWidth  = photoBitmap.getWidth();
                int sourceHeight = photoBitmap.getHeight();

                int scaledWidth = Math.min(sourceHeight, sourceWidth);
                int scaledHeight = (sourceHeight > sourceWidth)? sourceHeight - ( sourceHeight - sourceWidth) : sourceHeight;
                int scaledX = (sourceWidth - sourceHeight) / 2;
                scaledX = Math.max(scaledX, 0);
                int scaledY = (sourceHeight - sourceWidth) / 2;
                scaledY = Math.max(scaledY, 0);

                photoBitmap = Bitmap.createBitmap(photoBitmap,  scaledX, scaledY, scaledWidth, scaledHeight);

                photoBitmap = Bitmap.createScaledBitmap(photoBitmap,
                        PHOTO_WIDTH,
                        PHOTO_HEIGHT,
                        false);

                FileOutputStream fileOutputStream = new FileOutputStream(photoFile, false);

                photoBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);

                fileOutputStream.flush();
                fileOutputStream.close();
            }
        } catch (IOException e) {
            Log.e(TAG, "Compress photo error: " + e.getLocalizedMessage());
            e.printStackTrace();

Leo Huang

unread,
Nov 8, 2020, 10:55:25 PM11/8/20
to Alexander Popov, Android CameraX Discussion Group
Thanks for the information. Could it be caused by trying to load a corrupted file? 
Is there any IOException in the log during "cropAndCompressPhotoFile" or "EXIF overriding" when the issue happens?

Besides, how do you set up the use cases?
ex:
preview = new Preview.Builder()
                .setTargetAspectRatio(AspectRatio.RATIO_16_9)
                .setTargetRotation(rotation)
                .build()

preview.setSurfaceProvider(previewView.getSurfaceProvider())

imageCapture = new ImageCapture.Builder()
                .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
                .setTargetAspectRatio(AspectRatio.RATIO_16_9)
                .setTargetRotation(rotation)
                .build()

BTW, I was trying to reproduce it on CameraXBasic which also uses Glide to load saved photos, but not able to reproduce it.


Alexander Popov <ale...@nsysgroup.com> 於 2020年11月5日 週四 下午4:10寫道:

Alexander Popov

unread,
Nov 9, 2020, 2:48:23 AM11/9/20
to Android CameraX Discussion Group, leoh...@google.com, Android CameraX Discussion Group, Alexander Popov
I checked and didn't find any IOException in Logcat.

Here is my start camera code:

private void startCamera() {
showProgressBar();
ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext());
cameraProviderFuture.addListener(() -> {
try {
cameraProvider = cameraProviderFuture.get();

CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();

PreviewView cameraPreview = requireView().findViewById(R.id.camera_preview);

previewBuilder = new Preview.Builder();

Preview preview = previewBuilder
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
.build();

preview.setSurfaceProvider(cameraPreview.getSurfaceProvider());


imageCapture = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
.build();


if (flashButtonChecked) { imageCapture.setFlashMode(ImageCapture.FLASH_MODE_ON); }

cameraProvider.unbindAll();

camera = cameraProvider.bindToLifecycle(
this,
cameraSelector,
preview,
imageCapture);

tapToFocus(cameraPreview);

observeCameraState(cameraPreview);

} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Log.e(TAG, "Start camera error: " + e.toString());
}
}, ContextCompat.getMainExecutor(requireContext()));
}


Xi Zhang (张熹)

unread,
Nov 9, 2020, 12:20:49 PM11/9/20
to Alexander Popov, Android CameraX Discussion Group, leoh...@google.com
Alexander, I wonder what is the value of getPhotoFile() in your source code? Does it always point to the same file path?

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/f3038b9e-0022-4144-840e-0659162d06c8n%40android.com.
Message has been deleted

Alexander Popov

unread,
Nov 10, 2020, 3:04:27 AM11/10/20
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group, leoh...@google.com, Alexander Popov
Yes, in this case it always points to the same path.
I have the same file name because I need to rewrite a photo if it was shot the wrong way. My application takes specific shots in a concrete sequence.

Here is getPhotoFile code:   

 private File getPhotoFile() {
        File outputDirectory = Utils.getOutputDirectory(requireActivity());
        return new File(
                outputDirectory,
                photoSet.getFileName()
        );
}

getOutputDirectory method:

    public static File getOutputDirectory(Context context) {
        return context.getExternalFilesDir(LOCAL_FOLDER_NAME);
    }

getFileName method:

    public String getFileName() {
        return photos.get(currentPhotoNum).getFileName();

Xi Zhang (张熹)

unread,
Nov 11, 2020, 12:42:32 PM11/11/20
to Alexander Popov, Android CameraX Discussion Group, leoh...@google.com
Alexander, thanks for reporting. There seems to be a concurrent access issue in CameraX. We will address it in the next release. 

Xi Zhang (张熹)

unread,
Nov 17, 2020, 6:26:11 PM11/17/20
to Android CameraX Discussion Group, leoh...@google.com
Internal only: 

It's a bug in ImageCapture where the saving destination is accessed from multiple threads. See b/173019455.  The bug(s) is fixed, the work to enforce StrictMode in test apps is tracked by b/173019455 .

Alexander Popov

unread,
Nov 18, 2020, 4:17:24 AM11/18/20
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group
Thank you!

Alexander Popov

unread,
Jan 28, 2021, 5:31:33 AM1/28/21
to Android CameraX Discussion Group, Alexander Popov, Xi Zhang, Android CameraX Discussion Group
Hello!

I still have this issue on 1.0.0-rc02 and 1.0.0-alpha21.

Alexander Popov

unread,
Mar 2, 2021, 4:01:09 AM3/2/21
to Android CameraX Discussion Group, Alexander Popov, Xi Zhang, Android CameraX Discussion Group

Hello!

The issue finally fixed on 1.0.0-rc03. Thanks!

Android CameraX Discussion Group

unread,
Mar 2, 2021, 4:56:56 AM3/2/21
to Android CameraX Discussion Group, ale...@nsysgroup.com, Xi Zhang, Android CameraX Discussion Group
Glad to hear that. Thanks for the information!
Reply all
Reply to author
Forward
0 new messages