Browse Source

Fixed crash if referencing materials with techniques that don't exist.

JohnnyWahib 9 years ago
parent
commit
7a04075d82
1 changed files with 16 additions and 11 deletions
  1. 16 11
      Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

+ 16 - 11
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -187,19 +187,18 @@ class MaterialInspector extends ScriptWidget {
         var technique = <Atomic.Technique>cache.getResource("Technique", techniqueReverseLookup[techniqueName]);
         var technique = <Atomic.Technique>cache.getResource("Technique", techniqueReverseLookup[techniqueName]);
         var resourcePath = ToolCore.toolSystem.project.getResourcePath();
         var resourcePath = ToolCore.toolSystem.project.getResourcePath();
 
 
-        if (technique == null)
-            var techniquePath;
+        if (technique == null) {
+            var techniquePath = "";
 
 
-        for (var i in projectTechniques) {
-
-            if (techniqueName == projectTechniques[i]) {
-                techniquePath = projectTechniquesAddress[i];
-                break;
+            for (var i in projectTechniques) {
+                if (techniqueName == projectTechniques[i]) {
+                    techniquePath = projectTechniquesAddress[i];
+                    break;
+                }
             }
             }
+            techniquePath = techniquePath.replace(resourcePath, "");
+            technique = <Atomic.Technique>cache.getResource("Technique", techniquePath);
         }
         }
-        techniquePath = techniquePath.replace(resourcePath, "");
-        technique = <Atomic.Technique>cache.getResource("Technique", techniquePath);
-
         this.material.setTechnique(0, technique);
         this.material.setTechnique(0, technique);
     }
     }
 
 
@@ -209,7 +208,13 @@ class MaterialInspector extends ScriptWidget {
 
 
         var button = this.techniqueButton = new Atomic.UIButton();
         var button = this.techniqueButton = new Atomic.UIButton();
         var technique = this.material.getTechnique(0);
         var technique = this.material.getTechnique(0);
-        var techniqueName = technique.name.replace("Techniques/", "").replace(".xml", "");
+        var techniqueName = "";
+
+        if (technique != null) {
+            techniqueName = technique.name.replace("Techniques/", "").replace(".xml", "");
+        } else {
+            techniqueName = "UNDEFINED";
+        }
 
 
         button.text = techniqueName;
         button.text = techniqueName;