Skip to content

BatchNode: Fix IndexOutOfBoundsException #2297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jcfandino
Copy link
Contributor

@jcfandino jcfandino commented Jul 17, 2024

  • 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

- 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 jcfandino changed the title BatchNode: Fix IndexOutOfBoundsException (#2296) BatchNode: Fix IndexOutOfBoundsException Jul 17, 2024
@stephengold stephengold merged commit 1e10225 into jMonkeyEngine:master Jul 31, 2024
14 checks passed
@stephengold
Copy link
Member

@jcfandino thanks for your contribution

@stephengold stephengold added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Oct 22, 2024
@stephengold stephengold added this to the Future Release milestone Oct 22, 2024
@stephengold
Copy link
Member

This hasn't yet been integrated into the v3.7 branch, so it's not in 3.7.0-stable.

@yaRnMcDonuts yaRnMcDonuts modified the milestones: Future Release, v3.8.0 Dec 24, 2024
@pspeed42
Copy link
Contributor

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:

  1. have a bunch of larger meshes for one material (material A)
  2. add a few smaller meshes for another material (material B)
  3. batch()
  4. move one of the geometries for material A.

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.
0001-Alternate-fix-for-the-IndexOutOfBounds-exception-whe.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect".
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BatchNode can throw IndexOutOfBoundsException
4 participants