JVM crash while drawing a 0 vertex count mesh

On my MacBook, JVM crashes when BitmapText with text “” (length 0).

I don’t know what is the best solution for this bug.

  1. Fix for the BitmapText class only?
  2. Don’t render Mesh with vertex count 0



    I suggest the second solution.

    [patch]

    Index: src/jogl/com/jme3/renderer/jogl/JoglRenderer.java

    ===================================================================

    — src/jogl/com/jme3/renderer/jogl/JoglRenderer.java (revision 6467)

    +++ src/jogl/com/jme3/renderer/jogl/JoglRenderer.java (working copy)

    @@ -1066,6 +1066,8 @@

    }



    public void renderMesh(Mesh mesh, int lod, int count) {
  •    if (mesh.getVertexCount() == 0)<br />
    
  •        return;<br />
    

if (context.pointSize != mesh.getPointSize()) {

gl.glPointSize(mesh.getPointSize());

context.pointSize = mesh.getPointSize();

Index: src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java

===================================================================

— src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java (revision 6467)

+++ src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java (working copy)

@@ -2160,6 +2160,8 @@

}



public void renderMesh(Mesh mesh, int lod, int count) {

  •    if (mesh.getVertexCount() == 0)<br />
    
  •        return;<br />
    

if (context.pointSize != mesh.getPointSize()) {

glPointSize(mesh.getPointSize());

context.pointSize = mesh.getPointSize();

[/patch]

yeah the second solution looks better to me, since the mesh won’t be sent to the gpu.

Second solution sound better yes, since there are rare circumstances in other parts of the engine where you have a null mesh as well ( just say particles, morphing models and hard lod here)

Yes I agree with the 2nd solution

Thank you for the answers.

Committed rev. 6487

Sorry for the bump, but I’ve found that creating an empty mesh and rendering it will bypass this check where an empty mesh have a vertex count of -1. Either 1) a new empty mesh should have a vertex count of 0 ( which then willnot decrease the overall vertex count statistic) or 2 ) the renderMesh(Mesh mesh, int lod, int count) implementation should skip any vertex count <=0.
Form me the first solution is the better.
This caused me troubles where rendering an empty mesh resulted in a org.lwjgl.opengl.OpenGLException: Invalid value (1281)

Are you using 3.0 or the new 3.1? The latter has some fix related to this already… don’t know if it covers your issue but something was changed here.

Well there’s a somewhat related issue here:

How about this for both issues:

make the initial value -1.
Then in the update change that to 0 or higher depending on the actual mesh.
If getVertexCount/( is called and -1 is still present throw a hard exeption that the mesh is not properly updated.

This comes at the cost of an additional if however, but i guess the jvm would be intelligent enough to discard it quite soon as the field rarly changes at all.

To solve my problem I changed the value from -1 to 0 through reflexion. I don’t think that updating the count will work since you must have a Position buffer to update the value :

public void updateCounts(){
    [...]
    VertexBuffer pb = getBuffer(Type.Position);
    VertexBuffer ib = getBuffer(Type.Index);
    if (pb != null){
        vertCount = pb.getData().limit() / pb.getNumComponents(); <-- THIS WILL NEVER BE UPDATED IF THERE IS NO POSITION BUFFER
    }
    if (ib != null){
        elementCount = computeNumElements(ib.getData().limit());
    }else{
        elementCount = computeNumElements(vertCount);
    }
}

And to reply to @pspeed, i’m using 3.0 from the maven repo. However, from what I saw in the 3.1 Master, the problem might still be present.