From c289303228d48c4936426fceab357d9b60f3c224 Mon Sep 17 00:00:00 2001
From: soupday <79094830+soupday@users.noreply.github.com>
Date: Wed, 6 Oct 2021 02:25:12 +0100
Subject: [PATCH] 0.1.8b

Fix to GetMaxSize called with null textures in ComputeBake
---
 Editor/ComputeBake.cs | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/Editor/ComputeBake.cs b/Editor/ComputeBake.cs
index 4d80127..63fa152 100644
--- a/Editor/ComputeBake.cs
+++ b/Editor/ComputeBake.cs
@@ -42,6 +42,7 @@ public class ComputeBake
         private readonly List<string> importAssets;        
 
         public const int MAX_SIZE = 4096;
+        public const int MIN_SIZE = 128;
         public const string COMPUTE_SHADER = "RLBakeShader";
         public const string BAKE_FOLDER = "Baked";
         public const string TEXTURES_FOLDER = "Textures";
@@ -72,7 +73,8 @@ public ComputeBake(UnityEngine.Object character, CharacterInfo info)
 
         private static Vector2Int GetMaxSize(Texture2D a)
         {
-            Vector2Int max = new Vector2Int(a.width, a.height);
+            Vector2Int max = new Vector2Int(MIN_SIZE, MIN_SIZE);
+            if (a) max = new Vector2Int(a.width, a.height);
             if (max.x > MAX_SIZE) max.x = MAX_SIZE;
             if (max.y > MAX_SIZE) max.y = MAX_SIZE;
             return max;
@@ -80,9 +82,13 @@ private static Vector2Int GetMaxSize(Texture2D a)
 
         private static Vector2Int GetMaxSize(Texture2D a, Texture2D b)
         {
-            Vector2Int max = new Vector2Int(a.width, a.height);
-            if (b.width > max.x) max.x = b.width;
-            if (b.height > max.y) max.y = b.height;
+            Vector2Int max = new Vector2Int(MIN_SIZE, MIN_SIZE);
+            if (a) max = new Vector2Int(a.width, a.height);
+            if (b)
+            {
+                if (b.width > max.x) max.x = b.width;
+                if (b.height > max.y) max.y = b.height;
+            }
             if (max.x > MAX_SIZE) max.x = MAX_SIZE;
             if (max.y > MAX_SIZE) max.y = MAX_SIZE;
             return max;
@@ -90,11 +96,18 @@ private static Vector2Int GetMaxSize(Texture2D a, Texture2D b)
 
         private static Vector2Int GetMaxSize(Texture2D a, Texture2D b, Texture2D c)
         {
-            Vector2Int max = new Vector2Int(a.width, a.height);
-            if (b.width > max.x) max.x = b.width;
-            if (b.height > max.y) max.y = b.height;
-            if (c.width > max.x) max.x = c.width;
-            if (c.height > max.y) max.y = c.height;
+            Vector2Int max = new Vector2Int(MIN_SIZE, MIN_SIZE);
+            if (a) max = new Vector2Int(a.width, a.height);
+            if (b)
+            {
+                if (b.width > max.x) max.x = b.width;
+                if (b.height > max.y) max.y = b.height;
+            }
+            if (c)
+            {
+                if (c.width > max.x) max.x = c.width;
+                if (c.height > max.y) max.y = c.height;
+            }
             if (max.x > MAX_SIZE) max.x = MAX_SIZE;
             if (max.y > MAX_SIZE) max.y = MAX_SIZE;
             return max;