Revision: 64303
http://sourceforge.net/p/brlcad/code/64303
Author: starseeker
Date: 2015-02-26 23:17:28 +0000 (Thu, 26 Feb 2015)
Log Message:
-----------
Handle an error condition without crashing
Modified Paths:
--------------
brlcad/trunk/src/libbn/polygon.c
Modified: brlcad/trunk/src/libbn/polygon.c
===================================================================
--- brlcad/trunk/src/libbn/polygon.c 2015-02-26 21:45:18 UTC (rev 64302)
+++ brlcad/trunk/src/libbn/polygon.c 2015-02-26 23:17:28 UTC (rev 64303)
@@ -242,6 +242,8 @@
/**
* Implementation of Ear Clipping Polygon Triangulation
*
+ * Input polygon points must be in a CCW direction.
+ *
* Based off of David Eberly's documentation of the algorithm in Triangulation
* by Ear Clipping, section 2.
* http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
@@ -472,6 +474,7 @@
size_t i = 0;
size_t face_cnt = 0;
int offset = 0;
+ int ret = 0;
int *local_faces;
struct pt_lists *lists = NULL;
struct pt_vertex *v = NULL;
@@ -538,6 +541,12 @@
if (vref->v->isEar) PT_ADD_EAR_VREF(ear_list, vref->v, pts);
}
+ /* If we didn't find any ears, something is wrong - possibly non CCW
inputs */
+ if (BU_LIST_IS_EMPTY(&(lists->ear_list->l))) {
+ ret = 1;
+ goto cleanup;
+ }
+
/* We know what we need to begin - remove ears, build triangles and update
accordingly */
{
struct pt_vertex *one_vert = PT_NEXT(vertex_list);
@@ -567,9 +576,10 @@
(*faces)[i*3+1] = local_faces[i*3+1];
(*faces)[i*3+2] = local_faces[i*3+2];
}
+
+cleanup:
bu_free(local_faces, "free local faces array");
-
/* Make sure the lists are empty */
while (BU_LIST_WHILE(v, pt_vertex , &(vertex_list->l))) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits