BatchNode: Fix IndexOutOfBoundsException - #2297
Conversation
- There are temporary arrays that are reused to work with vertex buffers. - Some conditions cause the index to be used for storing more vertices that they can hold. - This throws the exception. - This fix validates the arrays size before accessing them, recreating the arrays if they are too small.
|
@jcfandino thanks for your contribution |
|
This hasn't yet been integrated into the v3.7 branch, so it's not in 3.7.0-stable. |
|
For what it's worth, I'm running an older version of JME that predates this fix and I ran across this during my live stream. After a little debugging, I know the exact cause of the issue and can guide to a more direct fix to the problem. The issue stems from the fact that doBatch() will only recalculate the maxVertCount for the geometries that it is rebatching. A specific scenario where this causes problems is:
The call to batch() would have recalculated maxVertCount as a value that is too small to redo the transforms of any of the objects for material A. This is because doBatch()'s gatherGeometries() call will only return the smaller geometries... the original material A geometries don't need to be rebatched. So while this PR is a really nice stop-gap to catch bugs and continue running, it didn't actually fix the bug... just hides it. (I still think the validateTempFloatArrays() is a good idea.) As it stands, though, the 'error case' will churn through more temporary buffer allocation than is needed. Once as an incorrect size when doBatch() is called and then again as a potentially incorrect size every time a larger geometry is moved. It's possible to get the maxVertCount right in doBatch(). Since gatherGeometries() is going to iterate over all of the geometries, anyway... this is where we should be calculating the maxVertCount. I don't have anything setup to do commits (yet) in modern jme github but I'm attaching a patch with my fix. |
There are temporary arrays that are reused to work with vertex buffers.
Some conditions cause the arrays to be used for storing more vertices that they can hold.
This throws the exception.
This fix validates the arrays size before accessing them, recreating the arrays if they are too small.
Fixes #2296