Program: 29956
Project: 29956
Buggy source:
void splitFaceInIntersections(final HE_Face f,final HE_Mesh mesh){
  Long[] intersectionVertices=new Long[2 * f.getFaceOrder()];
  Long[] polygon=new Long[2 * f.getFaceOrder()];
  int intersectionCount=0;
  int polygonCount=0;
  HE_FaceVertexCirculator fvCrc=f.fvCrc();
  HE_Vertex v;
  while (fvCrc.hasNext()) {
    v=fvCrc.next();
    polygon[polygonCount++]=v.getKey();
    if ((v.getTemporaryLabel() == ONVERTEX) || (v.getTemporaryLabel() == ONEDGE)) {
      intersectionVertices[intersectionCount++]=v.getKey();
      if (v.getTemporaryLabel() == ONVERTEX) {
        polygon[polygonCount++]=v.getKey();
      }
      v.clearVisited();
    }
  }
  if (intersectionCount < 2) {
    return;
  }
 else {
    intersectionVertices=Arrays.copyOf(intersectionVertices,intersectionCount);
    polygon=Arrays.copyOf(polygon,polygonCount);
    FastTable<Long[]> subPolygons=new FastTable<Long[]>();
    HE_Vertex v0=mesh.getVertexWithKey(intersectionVertices[0]);
    HE_Vertex v1;
    int i=1;
    do {
      v1=mesh.getVertexWithKey(intersectionVertices[i++]);
    }
 while (WB_Epsilon.isZeroSq(v0.getSqDistance3D(v1)));
    WB_Line intersectionLine=gf.createLineThroughPoints(v0,v1);
    Arrays.sort(intersectionVertices,new VertexOnLineComparator(mesh,intersectionLine));
    int trial=0;
    while (intersectionVertices.length > 1) {
      long key0=intersectionVertices[0];
      long key1=intersectionVertices[1];
      int index0=indexOf(key0,polygon);
      int index1=indexOf(key1,polygon);
      boolean solved=false;
      if (firstUnvisited(polygon,index0,mesh) == index1) {
        solved=true;
      }
 else {
        key1=intersectionVertices[0];
        key0=intersectionVertices[1];
        int tmp=index0;
        index0=index1;
        index1=tmp;
        if (firstUnvisited(polygon,index0,mesh) == index1) {
          solved=true;
        }
      }
      if (solved) {
        trial--;
        Long[] subPolygon=getSubPolygon(polygon,index0,index1);
        if (subPolygon.length > 2) {
          subPolygons.add(subPolygon);
        }
        polygon=getSubPolygon(polygon,index1,index0);
        intersectionVertices=Arrays.copyOfRange(intersectionVertices,2,intersectionVertices.length);
        if (intersectionVertices.length < 2) {
          subPolygons.add(polygon);
        }
        mesh.getVertexWithKey(key0).setVisited();
        mesh.getVertexWithKey(key1).setVisited();
      }
 else {
        trial++;
        reverse(intersectionVertices);
      }
      if (trial > 1) {
        break;
      }
    }
    for (    Long[] subPoly : subPolygons) {
      FastTable<HE_Halfedge> halfedges=new FastTable<HE_Halfedge>();
      HE_Halfedge he;
      HE_Face subFace=new HE_Face();
      subFace.copyProperties(f);
      for (int j=0; j < subPoly.length; j++) {
        he=new HE_Halfedge();
        if (subPoly[j] != subPoly[(j + 1) % subPoly.length]) {
          mesh.setVertex(he,mesh.getVertexWithKey(subPoly[j]));
          mesh.setHalfedge(he.getVertex(),he);
          mesh.setFace(he,subFace);
          halfedges.add(he);
          if (j == (subPoly.length - 1)) {
            he.setTemporaryLabel(1);
            cutEdges.add(he);
          }
        }
      }
      if (halfedges.size() > 2) {
        for (        HE_Halfedge fhe : halfedges) {
          if (fhe.getVertex().getTemporaryLabel() == FRONT) {
            front.add(subFace);
          }
 else           if (fhe.getVertex().getTemporaryLabel() == BACK) {
            back.add(subFace);
          }
        }
        mesh.setHalfedge(subFace,halfedges.get(0));
        for (int j=0, k=halfedges.size() - 1; j < halfedges.size(); k=j, j++) {
          mesh.setNext(halfedges.get(k),halfedges.get(j));
        }
        mesh.add(subFace);
        mesh.addHalfedges(halfedges);
      }
    }
    mesh.cutFace(f);
    mesh.pairHalfedges();
  }
}

Fixed version (ground truth):
void splitFaceInIntersections(final HE_Face f,final HE_Mesh mesh){
  Long[] intersectionVertices=new Long[2 * f.getFaceOrder()];
  Long[] polygon=new Long[2 * f.getFaceOrder()];
  int intersectionCount=0;
  int polygonCount=0;
  HE_FaceVertexCirculator fvCrc=f.fvCrc();
  HE_Vertex v;
  while (fvCrc.hasNext()) {
    v=fvCrc.next();
    polygon[polygonCount++]=v.getKey();
    if ((v.getTemporaryLabel() == ONVERTEX) || (v.getTemporaryLabel() == ONEDGE)) {
      intersectionVertices[intersectionCount++]=v.getKey();
      if (v.getTemporaryLabel() == ONVERTEX) {
        polygon[polygonCount++]=v.getKey();
      }
      v.clearVisited();
    }
  }
  if (intersectionCount < 2) {
    return;
  }
 else {
    intersectionVertices=Arrays.copyOf(intersectionVertices,intersectionCount);
    polygon=Arrays.copyOf(polygon,polygonCount);
    FastTable<Long[]> subPolygons=new FastTable<Long[]>();
    HE_Vertex v0=mesh.getVertexWithKey(intersectionVertices[0]);
    HE_Vertex v1;
    int i=1;
    do {
      v1=mesh.getVertexWithKey(intersectionVertices[i++]);
    }
 while (WB_Epsilon.isZeroSq(v0.getSqDistance3D(v1)) && (i < intersectionCount));
    WB_Line intersectionLine=gf.createLineThroughPoints(v0,v1);
    Arrays.sort(intersectionVertices,new VertexOnLineComparator(mesh,intersectionLine));
    int trial=0;
    while (intersectionVertices.length > 1) {
      long key0=intersectionVertices[0];
      long key1=intersectionVertices[1];
      int index0=indexOf(key0,polygon);
      int index1=indexOf(key1,polygon);
      boolean solved=false;
      if (firstUnvisited(polygon,index0,mesh) == index1) {
        solved=true;
      }
 else {
        key1=intersectionVertices[0];
        key0=intersectionVertices[1];
        int tmp=index0;
        index0=index1;
        index1=tmp;
        if (firstUnvisited(polygon,index0,mesh) == index1) {
          solved=true;
        }
      }
      if (solved) {
        trial--;
        Long[] subPolygon=getSubPolygon(polygon,index0,index1);
        if (subPolygon.length > 2) {
          subPolygons.add(subPolygon);
        }
        polygon=getSubPolygon(polygon,index1,index0);
        intersectionVertices=Arrays.copyOfRange(intersectionVertices,2,intersectionVertices.length);
        if (intersectionVertices.length < 2) {
          subPolygons.add(polygon);
        }
        mesh.getVertexWithKey(key0).setVisited();
        mesh.getVertexWithKey(key1).setVisited();
      }
 else {
        trial++;
        reverse(intersectionVertices);
      }
      if (trial > 1) {
        break;
      }
    }
    for (    Long[] subPoly : subPolygons) {
      FastTable<HE_Halfedge> halfedges=new FastTable<HE_Halfedge>();
      HE_Halfedge he;
      HE_Face subFace=new HE_Face();
      subFace.copyProperties(f);
      for (int j=0; j < subPoly.length; j++) {
        he=new HE_Halfedge();
        if (subPoly[j] != subPoly[(j + 1) % subPoly.length]) {
          mesh.setVertex(he,mesh.getVertexWithKey(subPoly[j]));
          mesh.setHalfedge(he.getVertex(),he);
          mesh.setFace(he,subFace);
          halfedges.add(he);
          if (j == (subPoly.length - 1)) {
            he.setTemporaryLabel(1);
            cutEdges.add(he);
          }
        }
      }
      if (halfedges.size() > 2) {
        for (        HE_Halfedge fhe : halfedges) {
          if (fhe.getVertex().getTemporaryLabel() == FRONT) {
            front.add(subFace);
          }
 else           if (fhe.getVertex().getTemporaryLabel() == BACK) {
            back.add(subFace);
          }
        }
        mesh.setHalfedge(subFace,halfedges.get(0));
        for (int j=0, k=halfedges.size() - 1; j < halfedges.size(); k=j, j++) {
          mesh.setNext(halfedges.get(k),halfedges.get(j));
        }
        mesh.add(subFace);
        mesh.addHalfedges(halfedges);
      }
    }
    mesh.cutFace(f);
    mesh.pairHalfedges();
  }
}