Custom mesh + picking = BIHTree Crash. (Fixed)

I’ve made a simple Circle class to outline planets and binary stars orbits that works fine but when those circles are attached to the scene node and iterate through the meshes when picking with a Ray I get a crash in BIHTree.



With no circles there’s no crash, so it’s either the BIHTree or the Circle class.



The picking is quite simple:

[java]

CollisionResults cr = new CollisionResults();

sceneNode.collideWith(ray, cr);

[/java]



The crash dump:

[java]

Oct 21, 2011 2:30:34 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.IndexOutOfBoundsException

at java.nio.Buffer.checkIndex(Buffer.java:532)

at java.nio.DirectFloatBufferU.get(DirectFloatBufferU.java:239)

at com.jme3.collision.bih.BIHTree.initTriList(BIHTree.java:97)

at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:127)

at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:131)

at com.jme3.scene.Mesh.createCollisionData(Mesh.java:828)

at com.jme3.scene.Mesh.collideWith(Mesh.java:844)

at com.jme3.scene.Geometry.collideWith(Geometry.java:338)

at com.jme3.scene.Node.collideWith(Node.java:494)

at com.madjack.games.disenthral.scenes.SolarSystemScene.pickTarget(SolarSystemScene.java:584)

at com.madjack.games.disenthral.Base$1.onAction(Base.java:327)

at com.jme3.input.InputManager.invokeActions(InputManager.java:183)

at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:418)

at com.jme3.input.InputManager.processQueue(InputManager.java:791)

at com.jme3.input.InputManager.update(InputManager.java:841)

at com.jme3.app.Application.update(Application.java:567)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:235)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:722)

[/java]



I’m not sure exactly what could cause this…

The issue is probably with your mesh data…

Here’s the Circle class. It’s loosely based on WireSphere. Care to point me out where the error could be/is? :slight_smile:



[java]

public final class Circle extends Mesh {



private final static int samples = 128;

private final static int zSamples = 1;



public Circle(float radius, float lineWidth) {

updatePositions(radius);

ShortBuffer ib = BufferUtils.createShortBuffer(samples * 4 + zSamples * samples * 2);

setBuffer(Type.Index, 2, ib);



int curNum = 0;

for (int j = 0; j < 2 + zSamples; j++) {

for (int i = curNum, k = curNum + samples - 1; i < k; i++) {

ib.put((short) i).put((short) (i + 1));

}

ib.put((short) (curNum + samples - 1)).put((short) curNum);

curNum += samples;

}



setMode(Mode.Lines);

setLineWidth(lineWidth);

updateBound();

updateCounts();

}



public void updatePositions(float radius) {

VertexBuffer pvb = getBuffer(Type.Position);

FloatBuffer pb;



if (pvb == null) {

pvb = new VertexBuffer(Type.Position);

pb = BufferUtils.createVector3Buffer(samples);

pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);

setBuffer(pvb);

} else {

pb = (FloatBuffer) pvb.getData();

}



pb.rewind();



float rate = FastMath.TWO_PI / (float) samples;

float angle = 0;

for (int i = 0; i < samples; i++){

float x;

float y;



x = radius * FastMath.cos(angle);

y = radius * FastMath.sin(angle);

pb.put(x).put(0).put(y);



angle += rate;

}

}

}

[/java]

Well, it looks to me from a quick read like you are creating a position buffer with 128 entries in it but then indexing into it as if there are 3 times that many.

1 Like

Fixed.



That’ll show me to copy/paste. :smiley:



Thanks Paul.

The bill is in the mail. :wink:

quickly switches number on the mailbox



Sure. Send it my way. :smiley: