From e24dcbbd7cf9902f226cd279dfe6fc2fb92f0d51 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Wed, 19 Jul 2017 00:28:36 -0400 Subject: [PATCH] Fixes a crash when a thumbnail for an image attachment fails to load. --- .../java/com/keylesspalace/tusky/ComposeActivity.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 0dfbd96c..0baa6bf9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -1365,6 +1365,10 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this, uri); Bitmap source = retriever.getFrameAtTime(); + if (source == null) { + displayTransientError(R.string.error_media_upload_opening); + return; + } Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); source.recycle(); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); @@ -1378,8 +1382,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm displayTransientError(R.string.error_media_upload_opening); return; } - Bitmap source = BitmapFactory.decodeStream(stream); + if (source == null) { + IOUtils.closeQuietly(stream); + displayTransientError(R.string.error_media_upload_opening); + return; + } Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); source.recycle(); try {