summaryrefslogtreecommitdiff
path: root/modules/csg/csg.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-04-28 12:33:23 -0300
committerJuan Linietsky <reduzio@gmail.com>2018-04-28 12:33:23 -0300
commitf8520dbba76fe989af189b287f1a54df0250ffa6 (patch)
treef72e93cf269a13cb67d1fd2b6794bc522be0107b /modules/csg/csg.cpp
parent93c77580aa8fb6b0af2905fef518ccc2c0a72e60 (diff)
-Changed how operators work, any shape can operate on any other
-Added some break condition for bad poly data to avoid editor freezes
Diffstat (limited to 'modules/csg/csg.cpp')
-rw-r--r--modules/csg/csg.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index e2da66a9f4..9752defa79 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -589,8 +589,6 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
edge_stack.push_back(es);
}
- int limit = p_poly.points.size() * 4;
-
//attempt to empty the stack.
while (edge_stack.size()) {
@@ -611,7 +609,9 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
edge_process[e.edge] = true; //mark as processed
- while (to_point != e.prev_point) {
+ int limit = p_poly.points.size() * 4; //avoid infinite recursion
+
+ while (to_point != e.prev_point && limit) {
Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
@@ -621,6 +621,9 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
t2d[2] = segment[1]; //origin
+ if (t2d.basis_determinant() == 0)
+ break; //abort poly
+
t2d.affine_invert();
//push all edges found here, they will be sorted by minimum angle later.
@@ -677,6 +680,8 @@ void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, in
to_point = next_point;
edge_process[next_edge] = true; //mark this edge as processed
current_edge = next_edge;
+
+ limit--;
}
//if more than 2 points were added to the polygon, add it to the list of polygons.
@@ -699,7 +704,9 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
int prev_point = p_from_point;
int to_point = p_to_point;
- while (to_point != p_from_point) {
+ int limit = p_poly.points.size() * 4; //avoid infinite recursion
+
+ while (to_point != p_from_point && limit) {
Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
//again create a transform to compute the angle.
@@ -707,6 +714,10 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
t2d[0] = (segment[1] - segment[0]).normalized(); //use as Y
t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
t2d[2] = segment[1]; //origin
+
+ if (t2d.basis_determinant() == 0)
+ break; //abort poly
+
t2d.affine_invert();
float max_angle;
@@ -734,6 +745,8 @@ void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_po
r_outline.push_back(to_point);
prev_point = to_point;
to_point = next_point_angle;
+
+ limit--;
}
}