Hello Everyone,
Been having some problems with BatchNode, first the stack trace.
java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkBounds(Buffer.java:567) ~[?:1.8.0_111]
at java.nio.DirectFloatBufferU.get(DirectFloatBufferU.java:265) ~[?:1.8.0_111]
at com.jme3.scene.BatchNode.doTransforms(BatchNode.java:547) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.BatchNode.updateSubBatch(BatchNode.java:152) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.BatchNode.onTransformChange(BatchNode.java:104) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Geometry.updateWorldTransforms(Geometry.java:326) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Spatial.updateGeometricState(Spatial.java:905) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.scene.Node.updateGeometricState(Node.java:271) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:245) ~[jme3-core-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151) ~[jme3-lwjgl-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197) ~[jme3-lwjgl-3.3.0-SNAPSHOT.jar:3.3-6587]
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232) ~[jme3-lwjgl-3.3.0-SNAPSHOT.jar:3.3-6587]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Background:
I have multiple different tree geometries that are batched together in a batch node. Trees are added and removed fairly regularly. There is also multiple materials being used, so there is a minimum of 2 subbatchs in the tree BatchNode.
The trees all have vertex paint on them rather than textures so they batch together nicely. Some of the trees have more vertices than others do. Which has caused a problem.
The issue:
bindBufPos.get(tmpFloat, 0, length);
tmpFloat is too small, when this is executed it throws an exception because its too small.
In the function doBatch() what happens is that when a full rebatch is not required, the vertex count is reset to zero using maxVertCount, however when its a partial rebatch this means that there has to be a geometry in the incoming group that has more vertices than whats already existing. Sometimes in my case this does not occur and then tmpFloat does not get set to a large enough size.
I have fixed my problem by changing line 200 to this
if (matMap.size() > 0 && needsFullRebatch) {
maxVertCount = 0;
}
however I am not sure if this will have a bad effect on other things.
I tried to recreate my problem in a single class for you guys to look at however for some reason the tmpFloat size was not being reduced when setting it at line 249, I’m not sure why that was happening and gave up trying to replicate my problem that way.
If you have any questions please let me know.
Thanks