Subject: CGAL users discussion list
List archive
- From: Laurent Rineau <>
- To:
- Subject: Re: [cgal-discuss] A simple question
- Date: Mon, 10 Dec 2007 14:21:05 +0100
- Organization: Inria, Sophia Antipolis, FRANCE
On Monday 10 December 2007 13:50:57
wrote:
> > Can you send us a *complete* little program, with the headers inclusions
> > and
> > your typedefs?
>
> Sorry...
I know have the explanation... The parameter P of your function app2, is a
copy: the edges/facets/vertices of the original polyhedron are copied. When
app2 returns, the returned handle is a handle to a facet of a temporary
object. After the return of app2, the copy is destroyed, and your variable
fd is a handle to an already destroyed object.
Make that change:
> Facet_handle app2( Polyhedron P){
> return P.facets_begin();}
into:
Facet_handle app2( Polyhedron& P) { // pass P by reference
return P.facets_begin();
}
If you do not need to modify your polyhedron, I suggest you to add "const"
qualifiers almost every where, and use const version of the polyhedron types.
That way, the compiler can make more optimizations, or triggers warning or
errors when you make some programming error like the one described above.
That is more difficult to write, because you need to think a bit, to know
where you can use const or not, but it is a good practice, as it make the
compiler verify more things.
I have attached your example, that I have constify to the most, maybe to
much. :-)
--
Laurent Rineau
INRIA - Sophia Antipolis
BP 93, 2004 Route des Lucioles
06902 Sophia Antipolis Cedex FRANCE
Tel: +33 4 92 38 78 62 (Fax: +33.4.97.15.53.95)
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Polyhedron_3.h> typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef Kernel::Point_3 Point_3; typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef Polyhedron::Facet_const_iterator Facet_const_iterator; typedef Polyhedron::Vertex_const_handle Vertex_const_handle; typedef Polyhedron::Halfedge_const_handle Halfedge_const_handle; const Facet_const_iterator app2(const Polyhedron& P) { return P.facets_begin(); } int main() { Polyhedron P; const Point_3 p1(0,0,0), p2(0,0,1), p3(0,1,0), p4(1,0,0); P.make_tetrahedron(p1,p2,p3,p4); const Vertex_const_handle& vh1 = P.facets_begin()->halfedge()->vertex(); const Facet_const_iterator& fd = app2(P); const Halfedge_const_handle& hh = fd->halfedge(); std::cerr << "All is ok." << std::endl; const Vertex_const_handle& vh2 = fd->halfedge()->vertex(); //segmentation fault return 0; }
- A simple question, gbatog, 12/10/2007
- Re: [cgal-discuss] A simple question, Laurent Rineau, 12/10/2007
- Re: [cgal-discuss] A simple question, gbatog, 12/10/2007
- Re: [cgal-discuss] A simple question, Daniel Duque Campayo, 12/10/2007
- Re: [cgal-discuss] A simple question, Laurent Rineau, 12/10/2007
- Re: [cgal-discuss] A simple question, gbatog, 12/10/2007
- Re: [cgal-discuss] A simple question, gbatog, 12/10/2007
- Re: [cgal-discuss] A simple question, Laurent Rineau, 12/10/2007
Archive powered by MHonArc 2.6.16.