Browse Source

Add error handling for loading bg2 icon

Despite the icon existing in the file system, the game is unable to load
the texture
habeebweeb 3 years ago
parent
commit
1372b09394
1 changed files with 13 additions and 4 deletions
  1. 13 4
      MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

+ 13 - 4
MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.cs

@@ -5779,7 +5779,7 @@ namespace CM3D2.MultipleMaids.Plugin
                 sortList.Sort((x, y) =>
                 {
                     int res = x.priority.CompareTo(y.priority);
-                    if (res == 0) res = x.name.CompareTo(y.name);
+                    if (res == 0) res = string.Compare(x.name, y.name);
                     return res;
                 });
             }
@@ -5798,13 +5798,22 @@ namespace CM3D2.MultipleMaids.Plugin
                         Texture2D texture2D;
                         if (string.IsNullOrEmpty(item.icon) || !GameUty.FileSystem.IsExistentFile(item.icon))
                         {
+                            Util.Logger.Log(Util.LogLevel.Warning, $"Could not find icon '{item.icon}' for menu '{item.menu}'");
                             return true;
                         }
                         else
                         {
-                            byte[] data = ImportCM.LoadTexture(GameUty.FileSystem, item.icon, false).data;
-                            texture2D = new Texture2D(50, 50, TextureFormat.RGB565, false);
-                            texture2D.LoadImage(data);
+                            try
+                            {
+                                byte[] data = ImportCM.LoadTexture(GameUty.FileSystem, item.icon, false).data;
+                                texture2D = new Texture2D(50, 50, TextureFormat.RGB565, false);
+                                texture2D.LoadImage(data);
+                            }
+                            catch
+                            {
+                                Util.Logger.Log(Util.LogLevel.Warning, $"Failed to load '{item.icon}' for menu '{item.menu}'");
+                                return true;
+                            }
                         }
                         item.tex = texture2D;
                     }