From 0186a20983be7b4f4c118d29b939f4018efe0dfb Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Wed, 20 Mar 2013 20:38:14 +0000 Subject: [PATCH] Fixed issue where the BAtchNode was throwing an ArrayIndexOutOfBound exception when batch was called twice in a row git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10496 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/BatchNode.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/engine/src/core/com/jme3/scene/BatchNode.java b/engine/src/core/com/jme3/scene/BatchNode.java index f1dfca402..2d8a20a02 100644 --- a/engine/src/core/com/jme3/scene/BatchNode.java +++ b/engine/src/core/com/jme3/scene/BatchNode.java @@ -185,8 +185,7 @@ public class BatchNode extends Node implements Savable { } protected void doBatch() { - Map> matMap = new HashMap>(); - maxVertCount = 0; + Map> matMap = new HashMap>(); int nbGeoms = 0; gatherGeomerties(matMap, this, needsFullRebatch); @@ -196,7 +195,12 @@ public class BatchNode extends Node implements Savable { } batches.clear(); batchesByGeom.clear(); + } + //only reset maxVertCount if there is something new to batch + if (matMap.size() > 0) { + maxVertCount = 0; } + for (Map.Entry> entry : matMap.entrySet()) { Mesh m = new Mesh(); Material material = entry.getKey(); @@ -238,12 +242,15 @@ public class BatchNode extends Node implements Savable { logger.log(Level.FINE, "Batched {0} geometries in {1} batches.", new Object[]{nbGeoms, batches.size()}); - - //init temp float arrays - tmpFloat = new float[maxVertCount * 3]; - tmpFloatN = new float[maxVertCount * 3]; - if (useTangents) { - tmpFloatT = new float[maxVertCount * 4]; + //init the temp arrays if something has been batched only. + if(matMap.size()>0){ + //TODO these arrays should be allocated by chunk instead to avoid recreating them each time the batch is changed. + //init temp float arrays + tmpFloat = new float[maxVertCount * 3]; + tmpFloatN = new float[maxVertCount * 3]; + if (useTangents) { + tmpFloatT = new float[maxVertCount * 4]; + } } }