Subject: CGAL users discussion list
List archive
- From: Sascha Brawer <>
- To:
- Cc: Daniel Berlin <>
- Subject: [cgal-discuss] Some patches for CGAL 4.0
- Date: Mon, 16 Apr 2012 16:11:20 +0200
Hello CGAL maintainers,
here's a couple of patches we found useful while playing around with the CGAL library.
Best regards, and thanks for the library!
-- Sascha Brawer,
**************************************************************************
We regularly check all libraries for memory leaks, using a heap checker that we've also released as open-source software: http://goog-perftools.sourceforge.net/ While doing this, we found a memory leak in CGAL v4.0, specifically in Parameterization_mesh_feature_extractor.h. The following patch would fix this leak:
--- CGAL-4.0/include/CGAL/Parameterization_mesh_feature_extractor.h 2012-01-13 19:25:35.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Parameterization_mesh_feature_extractor.h 2012-04-16 11:36:00.822320000 +0200
@@ -98,7 +98,12 @@
m_nb_borders = -1;
m_genus = -1;
}
- virtual ~Parameterization_mesh_feature_extractor() {}
+
+ virtual ~Parameterization_mesh_feature_extractor() {
+ for (typename Skeleton::iterator iter = m_skeleton.begin();
+ iter != m_skeleton.end(); ++iter)
+ delete *iter;
+ }
/// Get number of borders.
int get_nb_borders()
**************************************************************************
Likewise, the following patch seems to fix another memory leak:
--- CGAL-4.0/include/CGAL/Nef_3/SNC_FM_decorator.h 2012-01-13 19:25:29.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Nef_3/SNC_FM_decorator.h 2012-04-16 11:36:07.549770000 +0200
@@ -114,16 +114,26 @@
Halffacet_output(CGAL::Unique_hash_map<I,E>& F, std::vector<E>& S)
: From(F), Support(S) { edge_number=0; Support[0]=E(); }
+~Halffacet_output() {
+ for (int i = 0; i < vertices.size(); ++i) {
+ geninfo<unsigned>::clear(vertices[i]);
+ }
+}
+
+
typedef P Point;
typedef V Vertex_handle;
typedef unsigned Halfedge_handle;
+mutable vector<void*> vertices;
+
CGAL::Unique_hash_map<I,E>& From;
std::vector<E>& Support;
unsigned edge_number;
Vertex_handle new_vertex(const Point& p) const
{ geninfo<unsigned>::create(p.vertex()->info());
+ vertices.push_back(p.vertex()->info());
return p.vertex(); }
Halfedge_handle new_halfedge_pair_at_source(Vertex_handle v)
**************************************************************************
A fix for a potential bug in CGAL 4.0 (not 100% sure, you might want to double-check):
--- CGAL-4.0/include/CGAL/Triangulation_ds_circulators_2.h 2012-01-13 19:24:39.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Triangulation_ds_circulators_2.h 2012-04-16 11:36:02.079245000 +0200
@@ -382,7 +382,7 @@
else if (pos == Face_handle()) {pos = v->face();}
if (pos == Face_handle() || pos->dimension() < 1){
- _v = Vertex_handle(); pos = Face_handle(); return;}
+ _v = Vertex_handle(); pos = Face_handle(); _ri = 0; return;}
int i = pos->index(_v);
if (pos->dimension() == 2) {_ri = ccw(i);}
else {_ri = 1-i;}
**************************************************************************
The following patch fixes a memory leak in Sweep_line_2/Basic_sweep_line_2_impl.h. If m_num_of_subCurves is zero, CGAL would allocate a zero-length structure which then doesn't get freed. After the patch, it doesn't get allocated anymore when m_num_of_subCurves is zero.
--- CGAL-4.0/include/CGAL/Sweep_line_2/Basic_sweep_line_2_impl.h 2012-01-16 21:01:08.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Sweep_line_2/Basic_sweep_line_2_impl.h 2012-04-16 11:36:10.099633000 +0200
@@ -220,7 +220,9 @@
CGAL_assertion((m_statusLine.size() == 0));
// Allocate all of the Subcurve objects as one block.
- m_subCurves = m_subCurveAlloc.allocate(m_num_of_subCurves);
+ if (m_num_of_subCurves > 0) {
+ m_subCurves = m_subCurveAlloc.allocate(m_num_of_subCurves);
+ }
return;
}
**************************************************************************
The following patch avoids a compiler warning, so that people can compile CGAL without passing -Wno-parentheses:
--- CGAL-4.0/include/CGAL/Nef_2/PM_checker.h 2012-01-13 19:25:28.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Nef_2/PM_checker.h 2012-04-16 11:36:07.394797000 +0200
@@ -174,9 +174,9 @@
error_status << " el_forward = " << el_forward;
error_status << " is_left_turn = " << is_left_turn;
CGAL_assertion_msg( (ef == el ||
- ef_forward && !el_forward ||
- ef_forward && el_forward && is_left_turn ||
- !ef_forward && !el_forward && is_left_turn) ,
+ (ef_forward && !el_forward) ||
+ (ef_forward && el_forward && is_left_turn) ||
+ (!ef_forward && !el_forward && is_left_turn)) ,
error_status.str().c_str());
}
**************************************************************************
The following patch is helpful when compiling CGAL with c++11:
--- CGAL-4.0/include/CGAL/Constrained_triangulation_2.h 2012-01-17 21:01:00.000000000 +0100
+++ changed-CGAL-4.0/include/CGAL/Constrained_triangulation_2.h 2012-04-16 11:35:58.859492000 +0200
@@ -541,7 +541,7 @@
list_ab.push_back(Edge(lf, lf->index(current_face)));
list_ba.push_front(Edge(rf, rf->index(current_face)));
- intersected_faces.push_front(current_face);
+ intersected_faces.push_front(current_face.handle());
// initcd
previous_face=current_face;
@@ -574,7 +574,7 @@
}
else {
lf= current_face->neighbor(i2);
- intersected_faces.push_front(current_face);
+ intersected_faces.push_front(current_face.handle());
if (orient == LEFT_TURN)
list_ab.push_back(Edge(lf, lf->index(current_face)));
else // orient == RIGHT_TURN
@@ -590,7 +590,7 @@
// last triangle
vi = current_vertex;
- intersected_faces.push_front(current_face);
+ intersected_faces.push_front(current_face.handle());
lf= current_face->neighbor(cw(ind));
list_ab.push_back(Edge(lf, lf->index(current_face)));
rf= current_face->neighbor(ccw(ind));
- [cgal-discuss] Some patches for CGAL 4.0, Sascha Brawer, 04/16/2012
- Re: [cgal-discuss] Some patches for CGAL 4.0, Philipp Moeller, 04/17/2012
- Re: [cgal-discuss] Some patches for CGAL 4.0, Sascha Brawer, 04/17/2012
- Re: [cgal-discuss] Some patches for CGAL 4.0, Philipp Moeller, 04/17/2012
Archive powered by MHonArc 2.6.16.