From 2f4e6713907079ae96727b670de02d68ad4e5285 Mon Sep 17 00:00:00 2001
From: Mitchell McCaffrey <mitchemmc@gmail.com>
Date: Sun, 14 Feb 2021 08:35:43 +1100
Subject: [PATCH] Fix crash when unable to resize image

---
 src/helpers/image.js         |  2 +-
 src/modals/SelectMapModal.js | 18 ++++++++++--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/helpers/image.js b/src/helpers/image.js
index df9868a..6d011e2 100644
--- a/src/helpers/image.js
+++ b/src/helpers/image.js
@@ -39,7 +39,7 @@ export function getImageLightness(image) {
 
 /**
  * @typedef ResizedImage
- * @property {Blob} blob
+ * @property {Blob|null} blob The blob of the resized image, `null` if the image was unable to be resized to that dimension
  * @property {number} width
  * @property {number} height
  */
diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js
index 8f03924..f64b961 100644
--- a/src/modals/SelectMapModal.js
+++ b/src/modals/SelectMapModal.js
@@ -190,14 +190,16 @@ function SelectMapModal({
               file.type,
               resolution.quality
             );
-            const resizedBuffer = await blobToBuffer(resized.blob);
-            resolutions[resolution.id] = {
-              file: resizedBuffer,
-              width: resized.width,
-              height: resized.height,
-              type: "file",
-              id: resolution.id,
-            };
+            if (resized.blob) {
+              const resizedBuffer = await blobToBuffer(resized.blob);
+              resolutions[resolution.id] = {
+                file: resizedBuffer,
+                width: resized.width,
+                height: resized.height,
+                type: "file",
+                id: resolution.id,
+              };
+            }
           }
         }
         // Create thumbnail