Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Memory leak when using Polyhedron_3<EPECK>

Subject: CGAL users discussion list

List archive

[cgal-discuss] Memory leak when using Polyhedron_3<EPECK>


Chronological Thread 
  • From: Benjamin Kehlet <>
  • To: cgal-discuss <>
  • Subject: [cgal-discuss] Memory leak when using Polyhedron_3<EPECK>
  • Date: Wed, 17 Feb 2016 02:17:29 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:Cs2BrBeEK5FGLaeM5I5ibE2wlGMj4u6mDksu8pMizoh2WeGdxc6/Yh7h7PlgxGXEQZ/co6odzbGG7Oa8BSdbvd6oizMrTt9lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9HOnpAIma153xjLDtvcGPKF4UzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRuJN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IAu3GePEzQrVcSTgnKGso/9aj4RLMRA/K6noHWXgNiTJJBRLE5Vf0RMGinDH9s79X1S+YNMj3S/gXVDSm4rsjHBXljiUOMj862HrWj9F0heRdp0Ty9FRE34fIbdTNZ7JFdaTHcIZCSA==

Dear CGAL community

I am struggling with memory leaks when doing some simple manipulations of the geomtric locations of the vertices of a Polyhedron_3 when using the EPECK kernel.

Attached is the simplest example that reproduces the issue I could come up with. It is an implementation of a very simple smoothing scheme, which just replaces the location of every vertex with the centroid of its neighbors. The implementation does two passes: In the first pass the new locations are computed and collected in an std::vector<std::pair<Vertex_handle, Point_3>>. Then in the second pass the new locations are applied. This leaks heavily and the consumed memory (simply monitored with top) increases by each smoothing iteration.

Another strange thing is that when running "valgrind --tool=memcheck", I get this error
"""
terminate called after throwing an instance of 'CGAL::Assertion_exception'
  what():  CGAL ERROR: assertion violation!
Expr: -CGAL_IA_MUL(-1.1, 10.1) != CGAL_IA_MUL(1.1, 10.1)
File: /home/benjamik/software/CGAL-4.8-beta1/local/include/CGAL/Interval_nt.h
Line: 209
Explanation: Wrong rounding: did you forget the  -frounding-math  option if you use GCC (or  -fp-model strict  for Intel)?
"""
which doesn't show up when I just run the program (with a debug configuration of CGAL).

I am running CGAL-4.8-beta1 on Linux. I have tried this with both gcc 4.8.4 and gcc 5.3.1.

Any help would be highly appreciated!

Best regards

Benjamin Kehlet
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/centroid.h>
#include <string>
#include <fstream>

//----------------------------------------------------------------------------
template<typename Polyhedron>
static void smooth_simple(Polyhedron& p, int iterations)
//----------------------------------------------------------------------------
{
  typedef typename Polyhedron::Traits::Point_3 Point_3;
  typedef typename Polyhedron::Traits::Vector_3 Vector_3;
  typedef typename Polyhedron::Vertex_handle Vertex_handle;
  typedef typename Polyhedron::Halfedge_around_vertex_const_circulator HV_const_circulator;

  assert(p.is_valid());
  
  for (std::size_t iteration = 0; iteration < iterations; iteration++)
  {
    std::vector<std::pair<Vertex_handle, Point_3> > smoothed;

    std::cout << "Iteration " << iteration << std::endl;

    // Compute new location
    for (typename Polyhedron::Vertex_iterator vit = p.vertices_begin();
         vit != p.vertices_end();
         vit++)
    {
      std::vector<Point_3> neighbors;

      const HV_const_circulator h_start = vit->vertex_begin();
      HV_const_circulator h_current = h_start;
      do
      {
        neighbors.push_back(h_current->opposite()->vertex()->point());
        h_current++;
      } while (h_current != h_start);

      const Point_3 centroid = CGAL::centroid(neighbors.begin(), neighbors.end(), CGAL::Dimension_tag<0>());
      smoothed.push_back(std::make_pair(Vertex_handle(vit), centroid));
    }

    // Apply new locations
    for (typename std::vector<std::pair<Vertex_handle, Point_3> >::iterator it = smoothed.begin(); it != smoothed.end(); it++)
    {
      it->first->point() = it->second;
    }
  }
}
//----------------------------------------------------------------------------
int main(int argc, char** argv)
//----------------------------------------------------------------------------
{
  typedef CGAL::Polyhedron_3<CGAL::Exact_predicates_exact_constructions_kernel> Polyhedron;

  Polyhedron p;
  {
    std::ifstream infile(argv[1]);
    infile >> p;
  }
  std::cout << "Num vertices of polyhedron: " << p.size_of_vertices() << std::endl;
  const std::size_t iterations = 5;

  smooth_simple(p, iterations);

  std::ofstream outfile("smoothed.off");
  outfile << p;
}



Archive powered by MHonArc 2.6.18.

Top of Page