chrisidefix / cgal-bindings

Automatically exported from code.google.com/p/cgal-bindings
Boost Software License 1.0
0 stars 0 forks source link

segfault: del'ing Triangulation_2 edge returns face_handle to heap #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I get a segfault when I keep a reference to the face of an edge, but not the 
edge itself.

To reproduce the problem (also see attached script):
1. Create Constrained_Delaunay_triangulation_2
2. Force python to allocate enough memory to start reusing freed memory.
3. Add a small number of points with constraints between them
4. Query for incident constraints, retain a handle for the face, but not the 
edge.
5. The face is still referenced, but it's memory is overwritten by subsequent 
operations.
6. Further access to the face can lead to a segfault.

This happens on an up to date Ubuntu system, and appears to happen on OSX as 
well (same behavior, but I haven't been able to narrow it down as much)

CGAL: 4.2 (ubuntu)
boost: 1.53 (ubuntu)
SWIG: 2.0.10 (ubuntu)
Python: 2.7.5 (ubuntu)
cgal-bindings: from git as of 2013-12-05
compiled with gcc 4.8.1

Note that to trigger this error, it's necessary to have allocated enough 
objects so that the python memory manager will start reusing memory.

Original issue reported on code.google.com by RustyCh...@gmail.com on 5 Dec 2013 at 8:34

Attachments:

GoogleCodeExporter commented 9 years ago
The first problem I observe is not related to the memory. When del clist is 
processed, the internal class representing the face handle is deleted while it 
is still referenced by face. If my understanding of the swig code is correct, 
the face belongs to the pair and when the pair is deleted, the face is also 
deleted. I'll try to come up with a minimal example and post on the swig 
mailing list to be sure.

Original comment by sloriot...@gmail.com on 13 Dec 2013 at 7:42

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I don't know if this is the "proper" fix, but I have been able to run stably by 
adding a typemap in declare_triangulation_2.i which makes copies of the 
Face_handle when pulled out of an edge.  My attempt to do this in git (note 
that there are other changes in that repo related to adding support Apollonius 
Graphs, my next project...):

https://code.google.com/r/rustychris-apollonius/source/diff?spec=svnb297408ae5d7
01f365f856372b6622b3adc5e59d&r=b297408ae5d701f365f856372b6622b3adc5e59d&format=s
ide&path=/SWIG_CGAL/Triangulation_2/declare_triangulation_2.i

A regular diff is attached.

cheers

Original comment by RustyCh...@gmail.com on 14 Dec 2013 at 12:07

Attachments:

GoogleCodeExporter commented 9 years ago
This looks like a hack :) but agree that it should work in this specific case.
I made some tests and the problem seems to happen only when using the output 
iterator.
I sent an email to the swig mailing with a minimal example to see what is wrong 
with my code. As soon as I get an answer I let you know.

Original comment by sloriot...@gmail.com on 16 Dec 2013 at 7:12

GoogleCodeExporter commented 9 years ago
Any word from the swig folks?

thanks--

Original comment by RustyCh...@gmail.com on 20 Feb 2014 at 8:33

GoogleCodeExporter commented 9 years ago
Unfortunately no :( I need to invest some time to debug this.

Original comment by sloriot...@gmail.com on 20 Feb 2014 at 9:31