I have a buffer with capacity 3000.
i fill the first 300 elements, so the new limit becomes 300.
limit: 3000 becomes 300
i call Mesh.updateCounts()
vertex count : 3000 becomes 3000
[java]if (pb != null){
vertCount = pb.getData().capacity() / pb.getNumComponents();
}[/java]
Should become :
[java]if (pb != null){
vertCount = pb.getData().limit() / pb.getNumComponents();
}[/java]
This bug makes jme read after buffer limit which is illegal
Screenshot of jme reading beyond limit();
http://i.imgur.com/veKT5.png
To see if this bug is really a jme bug i do the following, ( i hack jme to allow me to run my code with reflection).
[java]
VertexBuffer pb = mesh.getBuffer(VertexBuffer.Type.Position);
try
{
Field field = mesh.getClass().getDeclaredField(“vertCount”);
field.setAccessible(true);
field.set(mesh, pb.getData().limit() / pb.getNumComponents());
}
catch (Exception e)
{
e.printStackTrace();
}
[/java]
Result :
limit: 3000 becomes 300
vertex count : 3000 becomes 300
Outcome :
http://i.imgur.com/th2Vh.png
Unsure if I should ask how long it took you to find the problem… Must have been a great hunt. lol
Good catch there.
I spend 2 days searching my code, testing if i somehow forgot to call a method, or if it was my bug.
today i inspected every jme method that i used, to see if something strange is happening under the hood.