From f6c309e7db7d1a6f7ee132f365f821b20ed09535 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 0dfbd96c8..0baa6bf9b 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 {