From aba48495e12ace8ef7001d22d794a5a39b529d0c Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sat, 25 Apr 2015 18:25:07 -0400 Subject: [PATCH] J3MLoader: enforce MaterialKey requirements based on extension --- .../java/com/jme3/material/plugins/J3MLoader.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java index 5d7f5ca8c..0c81c3e14 100644 --- a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java +++ b/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{