Exception IndexOutOfBounds on ray collides check

Hello there! Sorry about my English…

I try to use code from some forumes. For check mouse pointer was clicked on the some object into game menu.

On the line 57 I got exception, by click on any place of my menu:
(into “@Override public void onAnalog(String name, float value, float tpf) {…”)

03.10.24 04:26:59.098 [ERROR] th:jME3 Main c.j.a.LegacyApplication.handleError():666   Uncaught exception thrown in Thread[#64,jME3 Main,6,main]
java.lang.IndexOutOfBoundsException: null
	at java.base/java.nio.Buffer$1.apply(Buffer.java:757)
	at java.base/java.nio.Buffer$1.apply(Buffer.java:754)
	at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
	at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.nio.Buffer.checkIndex(Buffer.java:768)
	at java.base/java.nio.DirectFloatBufferU.get(DirectFloatBufferU.java:342)
	at com.jme3.collision.bih.BIHTree.initTriList(BIHTree.java:82)
	at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:128)
	at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:132)
	at com.jme3.scene.Mesh.createCollisionData(Mesh.java:987)
	at com.jme3.scene.Mesh.collideWith(Mesh.java:1034)
	at com.jme3.scene.Geometry.collideWith(Geometry.java:471)
	at com.jme3.scene.Node.collideWith(Node.java:619)
	at game.freya.gui.states.substates.global.MenuAnalogListener.onAnalog(MenuAnalogListener.java:57)
	at com.jme3.input.InputManager.invokeAnalogs(InputManager.java:250)
	at com.jme3.input.InputManager.invokeUpdateActions(InputManager.java:220)
	at com.jme3.input.InputManager.update(InputManager.java:924)
	at com.jme3.app.LegacyApplication.update(LegacyApplication.java:785)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:248)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglCanvas.runLoop(LwjglCanvas.java:231)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:1570)

Exception from here:

    /**
     * Checks the given index against the limit, throwing an {@link
     * IndexOutOfBoundsException} if it is greater than the limit
     * or is negative.
     */
    @ForceInline
    final int checkIndex(int i) {                       // package-private
        return Preconditions.checkIndex(i, limit, IOOBE_FORMATTER);
    }

before that:

PS: Using Java 22 | JME 3.6.1-stable

It’s failing to create the collision data for one of the meshes.

Most likely cause is bad geometry somewhere in the scene that you are trying to collide against.

But I have only Box(“mainMenuBackground”) by frame size, Quad(“menuGrayCorner”) on the left side of screen, for menu buttons and Quad(“userAvatar”) on the top right.

Box has (2f, 1.5f, 0f) sizes, gray Quad is a Geometry with Mesh, has two triangles inside, and avatar Quad is Geometry textured by image, drawn by Graphics2D.

It`s very strange. I think all must be correct…

If it were me, I’d write some debug code to traverse the scene to find all of the Geometry objects and call geom.getMesh().createCollisionData() to see which one is buggy.

1 Like