From 36b6ab32865c155a9413bd4a88dbe4515de77063 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 23 Oct 2011 21:03:39 +0000 Subject: [PATCH] * Prevent crash in Animation if no tracks are set on animation * Ogre3D .material files will still load even if a single texture is not found * Show any exceptions that occur in material loading (if any are thrown) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8519 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/animation/Animation.java | 3 +++ .../ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java | 9 ++++++++- .../src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/src/core/com/jme3/animation/Animation.java b/engine/src/core/com/jme3/animation/Animation.java index 330a5c885..ef1af1299 100644 --- a/engine/src/core/com/jme3/animation/Animation.java +++ b/engine/src/core/com/jme3/animation/Animation.java @@ -106,6 +106,9 @@ public class Animation implements Savable, Cloneable { * @param channel the animation channel */ void setTime(float time, float blendAmount, AnimControl control, AnimChannel channel, TempVars vars) { + if (tracks == null) + return; + for (int i = 0; i < tracks.length; i++){ tracks[i].setTime(time, blendAmount, control, channel, vars); } diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java index dbeaa2d33..4b4f115a9 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/MaterialLoader.java @@ -36,6 +36,7 @@ import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetKey; import com.jme3.asset.AssetLoader; import com.jme3.asset.AssetManager; +import com.jme3.asset.AssetNotFoundException; import com.jme3.asset.TextureKey; import com.jme3.material.Material; import com.jme3.material.MaterialList; @@ -140,7 +141,13 @@ public class MaterialLoader implements AssetLoader { key.setGenerateMips(genMips); key.setAsCube(cubic); - Texture loadedTexture = assetManager.loadTexture(key); + Texture loadedTexture; + try { + loadedTexture = assetManager.loadTexture(key); + } catch (AssetNotFoundException ex){ + logger.log(Level.WARNING, "Failed to load texture " + key + " for material " + matName, ex); + loadedTexture = null; + } if (loadedTexture == null){ ByteBuffer tempData = BufferUtils.createByteBuffer(3); tempData.put((byte)0xFF).put((byte)0x00).put((byte)0x00); diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java index 812858f26..db5eba180 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java @@ -785,12 +785,14 @@ public class MeshLoader extends DefaultHandler implements AssetLoader { materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + materialName + ".material")); } catch (AssetNotFoundException e) { logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, materialName, folderName, meshName, ext}); + logger.log(Level.WARNING, "", e); } } else { try { materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); } catch (AssetNotFoundException e) { logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, meshName, folderName, meshName, ext}); + logger.log(Level.WARNING, "", e); } } } @@ -799,7 +801,8 @@ public class MeshLoader extends DefaultHandler implements AssetLoader { materialList = (MaterialList) assetManager.loadAsset(new OgreMaterialKey(folderName + meshName + ".material")); } catch (AssetNotFoundException e) { logger.log(Level.WARNING, "Cannot locate {0}{1}.material for model {2}{3}.{4}", new Object[]{folderName, meshName, folderName, meshName, ext}); - } + logger.log(Level.WARNING, "", e); + } }