From be3dc06e28b1d2418cb902ac653d635c0e0c86e6 Mon Sep 17 00:00:00 2001 From: jmekaelthas Date: Thu, 17 Mar 2016 18:05:27 +0100 Subject: [PATCH] Bugfix: fixed a bug that caused NPE during vertex groups loading when mesh block was saved without its parent. --- .../plugins/blender/meshes/MeshHelper.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 5284b964a..49482c87f 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -286,30 +286,33 @@ public class MeshHelper extends AbstractBlenderHelper { List> result = new ArrayList>(); Structure parent = blenderContext.peekParent(); - Structure defbase = (Structure) parent.getFieldValue("defbase"); - List groupNames = new ArrayList(); - List defs = defbase.evaluateListBase(); - for (Structure def : defs) { - groupNames.add(def.getFieldValue("name").toString()); - } + if(parent != null) { + // the mesh might be saved without its parent (it is then unused) + Structure defbase = (Structure) parent.getFieldValue("defbase"); + List groupNames = new ArrayList(); + List defs = defbase.evaluateListBase(); + for (Structure def : defs) { + groupNames.add(def.getFieldValue("name").toString()); + } - Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices - if (pDvert.isNotNull()) {// assigning weights and bone indices - List dverts = pDvert.fetchData(); - for (Structure dvert : dverts) { - Map weightsForVertex = new HashMap(); - Pointer pDW = (Pointer) dvert.getFieldValue("dw"); - if (pDW.isNotNull()) { - List dw = pDW.fetchData(); - for (Structure deformWeight : dw) { - int groupIndex = ((Number) deformWeight.getFieldValue("def_nr")).intValue(); - float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue(); - String groupName = groupNames.get(groupIndex); + Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices + if (pDvert.isNotNull()) {// assigning weights and bone indices + List dverts = pDvert.fetchData(); + for (Structure dvert : dverts) { + Map weightsForVertex = new HashMap(); + Pointer pDW = (Pointer) dvert.getFieldValue("dw"); + if (pDW.isNotNull()) { + List dw = pDW.fetchData(); + for (Structure deformWeight : dw) { + int groupIndex = ((Number) deformWeight.getFieldValue("def_nr")).intValue(); + float weight = ((Number) deformWeight.getFieldValue("weight")).floatValue(); + String groupName = groupNames.get(groupIndex); - weightsForVertex.put(groupName, weight); + weightsForVertex.put(groupName, weight); + } } + result.add(weightsForVertex); } - result.add(weightsForVertex); } } return result;