From 16d6d2044d992a9adc20e1ddef74d867ffb9f745 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 23 Jan 2018 16:48:30 +0100 Subject: [PATCH] catch OutOfMemory errors at saving images --- .../simplemobiletools/camera/helpers/PhotoProcessor.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt index ff17f805..87cc2ae4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/PhotoProcessor.kt @@ -83,7 +83,11 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId } else { matrix.preScale(-1f, 1f) } - image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false) + try { + image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false) + } catch (e: OutOfMemoryError) { + activity.toast(R.string.out_of_memory_error) + } } image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos) @@ -140,7 +144,9 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId override fun onPostExecute(path: String) { super.onPostExecute(path) - activity.mediaSaved(path) + if (path.isNotEmpty()) { + activity.mediaSaved(path) + } } interface MediaSavedListener {