Browse Source

J3MLoader: enforce MaterialKey requirements based on extension

Kirill Vainer 10 years ago
parent
commit
aba48495e1

+ 7 - 5
jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

@@ -569,10 +569,15 @@ public class J3MLoader implements AssetLoader {
 
     public Object load(AssetInfo info) throws IOException {       
         this.assetManager = info.getManager();
-
+        
         InputStream in = info.openStream();        
         try {
-            key = info.getKey();            
+            key = info.getKey();
+            if (key.getExtension().equals("j3m") && !(key instanceof MaterialKey)) {
+                throw new IOException("Material instances must be loaded via MaterialKey");
+            } else if (key.getExtension().equals("j3md") && key instanceof MaterialKey) {
+                throw new IOException("Material definitions must be loaded via AssetKey");
+            }
             loadFromRoot(BlockLanguageParser.parse(in));
         } finally {
             if (in != null){
@@ -581,9 +586,6 @@ public class J3MLoader implements AssetLoader {
         }
         
         if (material != null){
-            if (!(info.getKey() instanceof MaterialKey)){
-                throw new IOException("Material instances must be loaded via MaterialKey");
-            }
             // material implementation
             return material;
         }else{