summaryrefslogtreecommitdiffstats
path: root/modules/csg/csg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/csg/csg.cpp')
-rw-r--r--modules/csg/csg.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index f399466fe5..c1fe11d6aa 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -409,6 +409,9 @@ void CSGBrushOperation::BuildPoly::clip(const CSGBrush *p_brush, int p_face, Mes
//transform A points to 2D
+ if (segment[0].distance_to(segment[1]) < CMP_EPSILON)
+ return; //too small
+
_clip_segment(p_brush, p_face, segment, mesh_merge, p_for_B);
}
@@ -586,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()) {
@@ -608,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 };
@@ -618,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.
@@ -674,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.
@@ -696,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.
@@ -704,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;
@@ -731,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--;
}
}
@@ -1216,7 +1232,7 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() {
center /= 3.0;
Plane plane(points[faces[i].points[0]], points[faces[i].points[1]], points[faces[i].points[2]]);
- Vector3 target = center + plane.normal * max_distance;
+ Vector3 target = center + plane.normal * max_distance + Vector3(0.0001234, 0.000512, 0.00013423); //reduce chance of edge hits by doing a small increment
int intersections = _bvh_count_intersections(bvh, max_depth, max_alloc - 1, center, target, i);
@@ -1239,7 +1255,7 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 &p_a, const Vector3 &p
vk.z = int((double(src_points[i].z) + double(vertex_snap) * 0.31234) / double(vertex_snap));
int res;
- if (snap_cache.lookup(vk, &res)) {
+ if (snap_cache.lookup(vk, res)) {
indices[i] = res;
} else {
indices[i] = points.size();