Polygon tesselation errors

I have looked at some sample code for polygon tesselation over here (I’m using their implementation of the callback class too) and gave it a shot for my own polygons (can reach up to 60.000 points). The problem is that for small polygons which I enter exactly like the example, everything is fine, but for the generated ones I get some errors.

First of all, the error string lookup seems in the callback class seems bugged
(see this link) but I don’t mind much for that since I’ll simply google the integer error codes.
My error function from the callback which crashes because error code lookups fail;

        
public void error(int errnum) {
            try {
                System.err.println("Tesselation Error(errnum): " + errnum);
                String estring = glu.gluErrorString(errnum);
                System.err.println("Tesselation Error: " + estring);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
my debug statement containing the error code;
Tesselation Error(errnum): 100156

stacktrace;
java.lang.ArrayIndexOutOfBoundsException: 6
        at com.sun.opengl.impl.error.Error.gluErrorString(Error.java:95)
        at javax.media.opengl.glu.GLU.gluErrorString(GLU.java:240)


But my concern is that calling glu.gluTessEndPolygon in the end yields error code 100156 for my code. The code works if I comment out my own loop. I’m clueless as to what is wrong, could anyone provide a hint?


        tessellCallBack tessCallback = new tessellCallBack(gl, glu);
        listid = gl.glGenLists(1);
        GLUtessellator tobj = glu.gluNewTess();

        glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback);// glVertex3dv);
        glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback);// beginCallback);
        glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback);// endCallback);
        glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback);// errorCallback);

        double tri[][] = new double[][]{// [3][3]
            {0.75, 1.80, 1},
            {1.75, 0.75, 1},
            {1.25, 1.75, 1}
        };

        gl.glNewList(listid, GL.GL_COMPILE);
        gl.glShadeModel(GL.GL_FLAT);
        glu.gluTessBeginPolygon(tobj, null);
        glu.gluTessBeginContour(tobj);
        glu.gluTessVertex(tobj, tri[0], 0, tri[0]);
        glu.gluTessVertex(tobj, tri[1], 0, tri[1]);
        glu.gluTessVertex(tobj, tri[2], 0, tri[2]);
        glu.gluTessEndContour(tobj);

          glu.gluTessBeginContour(tobj);
          for (int i = 0; i < len; i++) {
              //get x/y/z values
              double[] tmp = new double[]{x, y, z};
              glu.gluTessVertex(tobj, tmp, 0, tmp);
          }
          glu.gluTessEndContour(tobj);

        glu.gluTessEndPolygon(tobj); //crash, error code 100156 
        gl.glEndList();
        glu.gluDeleteTess(tobj);

Try using the DebugGL pipeline instead of the standard GL. This will call glGetError after every call to a gl method and throw an exception if there is an error. This way you can find exactly which call (and when) is causing the bugs.

To use the DebugGL, in your init method do something like:
drawable.setGL(new DebugGL(drawable.getGL()));

I’ve a look in the JOGL code and found that error 100156 is GLU_TESS_ERROR6.
However, in JOGL gluErrorString is not able to give the proper string relative to GLU_TESS_ERROR6 and throw an ArrayOutOfBoundsException instead.
I reported the problem some time ago (https://jogl.dev.java.net/issues/show_bug.cgi?id=335), but the issue is still not fixed.

I used to have GLU_TESS_ERROR5, which meant that I was using some vertex containing nan or inf values.

If you want the result of gluErrorString you may have a try gluErrorString(GLU_TESS_ERROR6) with a standard C code.