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
3.0
rem..om 12 years ago
parent 05e080100e
commit 0186a20983
  1. 11
      engine/src/core/com/jme3/scene/BatchNode.java

@ -186,7 +186,6 @@ public class BatchNode extends Node implements Savable {
protected void doBatch() { protected void doBatch() {
Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>(); Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>();
maxVertCount = 0;
int nbGeoms = 0; int nbGeoms = 0;
gatherGeomerties(matMap, this, needsFullRebatch); gatherGeomerties(matMap, this, needsFullRebatch);
@ -197,6 +196,11 @@ public class BatchNode extends Node implements Savable {
batches.clear(); batches.clear();
batchesByGeom.clear(); batchesByGeom.clear();
} }
//only reset maxVertCount if there is something new to batch
if (matMap.size() > 0) {
maxVertCount = 0;
}
for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) { for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) {
Mesh m = new Mesh(); Mesh m = new Mesh();
Material material = entry.getKey(); Material material = entry.getKey();
@ -238,7 +242,9 @@ public class BatchNode extends Node implements Savable {
logger.log(Level.FINE, "Batched {0} geometries in {1} batches.", new Object[]{nbGeoms, batches.size()}); logger.log(Level.FINE, "Batched {0} geometries in {1} batches.", new Object[]{nbGeoms, batches.size()});
//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 //init temp float arrays
tmpFloat = new float[maxVertCount * 3]; tmpFloat = new float[maxVertCount * 3];
tmpFloatN = new float[maxVertCount * 3]; tmpFloatN = new float[maxVertCount * 3];
@ -246,6 +252,7 @@ public class BatchNode extends Node implements Savable {
tmpFloatT = new float[maxVertCount * 4]; tmpFloatT = new float[maxVertCount * 4];
} }
} }
}
//in case the detached spatial is a node, we unbatch all geometries in its subegraph //in case the detached spatial is a node, we unbatch all geometries in its subegraph
@Override @Override

Loading…
Cancel
Save