+ if(clipres > 0) {
+ /* polygon completely in the positive subspace */
+ if(!(tmp = dynarr_push(front_polys, polyarr + i))) {
+ fprintf(stderr, "build_tree: failed to reallocate polygon array\n");
+ goto fail;
+ }
+ front_polys = tmp;
+
+ } else if(clipres < 0) {
+ /* polygon completely in the negative subspace */
+ if(!(tmp = dynarr_push(back_polys, polyarr + i))) {
+ fprintf(stderr, "build_tree: failed to reallocate polygon array\n");
+ goto fail;
+ }
+ back_polys = tmp;
+
+ } else {
+ /* polygon is straddling the plane */
+ struct bsppoly poly;
+ poly.plane = polyarr[i].plane;
+
+ if(init_poly_noplane(&poly, clipped, clipped_vnum) == -1) {
+ goto fail;
+ }
+ if(!(tmp = dynarr_push(front_polys, &poly))) {
+ fprintf(stderr, "build_tree: failed to reallocate polygon array\n");
+ free(poly.verts);
+ goto fail;
+ }
+ front_polys = tmp;
+
+ if(init_poly_noplane(&poly, clipped_neg, clipped_neg_vnum) == -1) {
+ goto fail;
+ }
+ if(!(tmp = dynarr_push(back_polys, &poly))) {
+ fprintf(stderr, "build_tree: failed to reallocate polygon array\n");
+ free(poly.verts);
+ goto fail;
+ }
+ back_polys = tmp;
+
+ /* we allocated new sub-polygons, so we need to free the original vertex array */
+ free(polyarr[i].verts);