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)
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)
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.