Program: 70887
Project: 70887
Buggy source:
private void drawFacesRaw(GLRenderer renderer,PolygonalMesh mesh,TextureProps textureProps,int flags){
  Vector3d nrm;
  Vector3d[] nrms=null;
  Vector3d vtxNrm=new Vector3d();
  RenderProps.Shading savedShadeModel=renderer.getShadeModel();
  GL2 gl=renderer.getGL2();
  boolean computeVertexNormals=(flags & COMPUTE_VERTEX_NORMALS) != 0;
  boolean useRenderNormals=mesh.isRenderBuffered() && !mesh.isFixed();
  boolean useVertexColors=(flags & GLRenderer.VERTEX_COLORING) != 0;
  boolean useHSVInterpolation=(flags & GLRenderer.HSV_COLOR_INTERPOLATION) != 0;
  boolean useTextureCoords=(textureProps != null && textureProps.isEnabled() && !textureProps.isAutomatic() && mesh.myTextureIndices != null);
  boolean mergeQuadTriangles=(savedShadeModel != Shading.FLAT);
  if ((flags & IS_SELECTING) != 0) {
    useVertexColors=false;
  }
  if (!useNewRenderNormals && computeVertexNormals) {
    nrms=new Vector3d[mesh.numVertices()];
    for (int v=0; v < mesh.numVertices(); v++) {
      nrms[v]=new Vector3d();
      if (useRenderNormals) {
        mesh.getVertices().get(v).computeRenderNormal(nrms[v]);
      }
 else {
        mesh.getVertices().get(v).computeNormal(nrms[v]);
      }
    }
  }
  if (useVertexColors && useHSVInterpolation) {
    useHSVInterpolation=setupHSVInterpolation(gl);
  }
  myLastEdgeCnt=0;
  ArrayList<Face> faceList=mesh.getFaces();
  int[] faceOrder=mesh.getFaceOrder();
  int faceIdx;
synchronized (mesh) {
    int[] indexOffs=mesh.getFeatureIndexOffsets();
    int[] normalIndices=mesh.getNormalIndices();
    for (int i=0; i < faceList.size(); i++) {
      if (faceOrder == null) {
        faceIdx=i;
      }
 else {
        faceIdx=faceOrder[i];
      }
      faceIdx=unpackEdges(faceList,faceIdx,mergeQuadTriangles);
      Face face=faceList.get(faceIdx);
      if (myEdgeCnt > 4) {
        gl.glBegin(GL2.GL_POLYGON);
      }
 else       if (myLastEdgeCnt != myEdgeCnt) {
        if (myLastEdgeCnt == 3 || myLastEdgeCnt == 4) {
          gl.glEnd();
        }
        if (myEdgeCnt == 3) {
          gl.glBegin(GL2.GL_TRIANGLES);
        }
 else {
          gl.glBegin(GL2.GL_QUADS);
        }
      }
      if (!computeVertexNormals) {
        Vector3d faceNrm;
        if (useRenderNormals) {
          faceNrm=face.getRenderNormal();
        }
 else {
          faceNrm=face.getNormal();
        }
        gl.glNormal3d(faceNrm.x,faceNrm.y,faceNrm.z);
      }
      for (int edgeIdx=0; edgeIdx < myEdgeCnt; edgeIdx++) {
        HalfEdge he=myEdges[edgeIdx];
        int vi=(edgeIdx <= 2 ? edgeIdx : 2);
        int faceOff=indexOffs[he.face.idx];
        Vertex3d vtx=he.head;
        Point3d pnt=useRenderNormals ? vtx.myRenderPnt : vtx.pnt;
        if (computeVertexNormals) {
          if (useNewRenderNormals) {
            int nidx=normalIndices[faceOff + vi];
            if (nidx != -1) {
              float[] vec=mesh.myRenderNormals[nidx];
              gl.glNormal3f(vec[0],vec[1],vec[2]);
            }
          }
 else {
            HalfEdge lastHard=he.lastHardEdge();
            if (lastHard != null) {
              lastHard.computeVertexNormal(vtxNrm,useRenderNormals);
              gl.glNormal3d(vtxNrm.x,vtxNrm.y,vtxNrm.z);
            }
 else {
              nrm=nrms[he.head.idx];
              gl.glNormal3d(nrm.x,nrm.y,nrm.z);
            }
          }
        }
        if (useTextureCoords) {
          int iv=mesh.myTextureIndices[faceOff + vi];
          Vector3d vtext=mesh.myTextureCoords.get(iv);
          double sss=vtext.x;
          double ttt=vtext.y;
          gl.glTexCoord2f((float)sss,(float)(1 - ttt));
        }
        if (useVertexColors) {
          float[] color=null;
          int ci=mesh.myColorIndices[faceOff + vi];
          if (ci == -1) {
            color=null;
          }
 else {
            color=mesh.myColors.get(ci);
          }
          setVertexColor(gl,color,useHSVInterpolation);
        }
        gl.glVertex3d(pnt.x,pnt.y,pnt.z);
      }
      if (myEdgeCnt > 4) {
        gl.glEnd();
      }
      myLastEdgeCnt=myEdgeCnt;
    }
    if (myLastEdgeCnt == 3 || myLastEdgeCnt == 4) {
      gl.glEnd();
    }
  }
  if (useVertexColors && useHSVInterpolation) {
    gl.glUseProgramObjectARB(0);
  }
}

Fixed version (ground truth):
private void drawFacesRaw(GLRenderer renderer,PolygonalMesh mesh,TextureProps textureProps,int flags){
  Vector3d[] nrms=null;
  Vector3d vtxNrm=new Vector3d();
  RenderProps.Shading savedShadeModel=renderer.getShadeModel();
  GL2 gl=renderer.getGL2();
  boolean computeVertexNormals=(flags & COMPUTE_VERTEX_NORMALS) != 0;
  boolean useRenderNormals=mesh.isRenderBuffered() && !mesh.isFixed();
  boolean useVertexColors=(flags & GLRenderer.VERTEX_COLORING) != 0;
  boolean useHSVInterpolation=(flags & GLRenderer.HSV_COLOR_INTERPOLATION) != 0;
  boolean useTextureCoords=(textureProps != null && textureProps.isEnabled() && !textureProps.isAutomatic() && mesh.myTextureIndices != null);
  boolean mergeQuadTriangles=(savedShadeModel != Shading.FLAT);
  if ((flags & IS_SELECTING) != 0) {
    useVertexColors=false;
  }
  if (!useNewRenderNormals && computeVertexNormals) {
    nrms=new Vector3d[mesh.numVertices()];
    for (int v=0; v < mesh.numVertices(); v++) {
      nrms[v]=new Vector3d();
      if (useRenderNormals) {
        mesh.getVertices().get(v).computeRenderNormal(nrms[v]);
      }
 else {
        mesh.getVertices().get(v).computeNormal(nrms[v]);
      }
    }
  }
  if (useVertexColors && useHSVInterpolation) {
    useHSVInterpolation=setupHSVInterpolation(gl);
  }
  myLastEdgeCnt=0;
  ArrayList<Face> faceList=mesh.getFaces();
  int[] faceOrder=mesh.getFaceOrder();
  int faceIdx;
synchronized (mesh) {
    int[] indexOffs=mesh.getFeatureIndexOffsets();
    int[] normalIndices=mesh.getNormalIndices();
    int[] cidxs=useVertexColors ? mesh.getColorIndices() : null;
    ArrayList<float[]> colors=useVertexColors ? mesh.getColors() : null;
    for (int i=0; i < faceList.size(); i++) {
      if (faceOrder == null) {
        faceIdx=i;
      }
 else {
        faceIdx=faceOrder[i];
      }
      faceIdx=unpackEdges(faceList,faceIdx,mergeQuadTriangles);
      Face face=faceList.get(faceIdx);
      if (myEdgeCnt > 4) {
        gl.glBegin(GL2.GL_POLYGON);
      }
 else       if (myLastEdgeCnt != myEdgeCnt) {
        if (myLastEdgeCnt == 3 || myLastEdgeCnt == 4) {
          gl.glEnd();
        }
        if (myEdgeCnt == 3) {
          gl.glBegin(GL2.GL_TRIANGLES);
        }
 else {
          gl.glBegin(GL2.GL_QUADS);
        }
      }
      if (!computeVertexNormals) {
        Vector3d faceNrm;
        if (useRenderNormals) {
          faceNrm=face.getRenderNormal();
        }
 else {
          faceNrm=face.getNormal();
        }
        gl.glNormal3d(faceNrm.x,faceNrm.y,faceNrm.z);
      }
      for (int edgeIdx=0; edgeIdx < myEdgeCnt; edgeIdx++) {
        HalfEdge he=myEdges[edgeIdx];
        int vi=(edgeIdx <= 2 ? edgeIdx : 2);
        int faceOff=indexOffs[he.face.idx];
        Vertex3d vtx=he.head;
        Point3d pnt=useRenderNormals ? vtx.myRenderPnt : vtx.pnt;
        if (computeVertexNormals) {
          if (useNewRenderNormals) {
            int nidx=normalIndices[faceOff + vi];
            if (nidx != -1) {
              float[] nrm=mesh.myRenderNormals[nidx];
              gl.glNormal3f(nrm[0],nrm[1],nrm[2]);
            }
          }
 else {
            HalfEdge lastHard=he.lastHardEdge();
            if (lastHard != null) {
              lastHard.computeVertexNormal(vtxNrm,useRenderNormals);
              gl.glNormal3d(vtxNrm.x,vtxNrm.y,vtxNrm.z);
            }
 else {
              Vector3d nrm=nrms[he.head.idx];
              gl.glNormal3d(nrm.x,nrm.y,nrm.z);
            }
          }
        }
        if (useTextureCoords) {
          int iv=mesh.myTextureIndices[faceOff + vi];
          Vector3d vtext=mesh.myTextureCoords.get(iv);
          double sss=vtext.x;
          double ttt=vtext.y;
          gl.glTexCoord2f((float)sss,(float)(1 - ttt));
        }
        if (useVertexColors) {
          float[] color=null;
          int ci=cidxs[faceOff + vi];
          if (ci == -1) {
            color=null;
          }
 else {
            color=colors.get(ci);
          }
          setVertexColor(gl,color,useHSVInterpolation);
        }
        gl.glVertex3d(pnt.x,pnt.y,pnt.z);
      }
      if (myEdgeCnt > 4) {
        gl.glEnd();
      }
      myLastEdgeCnt=myEdgeCnt;
    }
    if (myLastEdgeCnt == 3 || myLastEdgeCnt == 4) {
      gl.glEnd();
    }
  }
  if (useVertexColors && useHSVInterpolation) {
    gl.glUseProgramObjectARB(0);
  }
}