Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Problem with storing handles as member objects

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Problem with storing handles as member objects


Chronological Thread 
  • From: Costas Tsirogiannis <>
  • To:
  • Subject: Re: [cgal-discuss] Problem with storing handles as member objects
  • Date: Wed, 7 Jul 2010 13:56:18 +0200
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=vdd01ZcIEMs/cwDXm8p9kGTyZdBS4lu7x4bWWrruBbe0Z/ugaEjMaN8pEP5cAwQG1I 5Nd0SAIoMsznEJ32QShlFFOR+pkF2VY5zK9nNO5r2irxgSdtQheY31W0sQZTzFQ2+0Cr ErNwXnzk3g2xyKGgsoReQldXRJZh25gFbZ8lU=

  I checked if there is any member object that is not assigned properly but there is no issue there.

 Here's where I think the problem is:

Assume that you have class that stores a member handle

class Myclass {
....

private:

Kind_of_handle _h;

public:

void set_handle( Kind_of_handle &h)
{ _h = h;}

Kind_of_handle
get_handle(void)
{ return _h;}

} ;


* Assume you have two subsequent calls of some functions A() , B() :

int main(){

Myclass mc;

A(mc);
B(mc);

return 0;
}


void A( Myclass &c)
{
Kind_of_handle hndl;
....
mc.set_handle(hndl);
Kind_of_handle hndl2 = mc.get_handle();
std::cout << hndl2->info() << std::endl;
}

void B( Myclass &c)
{
Kind_of_handle hndl3 = mc.get_handle();
std::cout << hndl3->info() << std::endl;
}

What happens to me is that the std::cout in function A works fine
while the std::cout in function B returns a segmentation fault.

It seems that copying a handle h1 to another handle  h2 is ok
until the scope of h1 is over. After that h2 is not reliable.
Does this make sense? If yes, how do I go around it?
Whether these handles are stored in objects or not does not seem
to be an issue that creates this error.

thanks

Constantinos



 

On Tue, Jul 6, 2010 at 11:05 PM, Sebastien Loriot (GeometryFactory) <sloriot.ml@gmail.com> wrote:
Costas Tsirogiannis wrote:
 I have not defined a copy constructor for the augmented half-edges, would that change something here?
So no, the default should be fine.



On Tue, Jul 6, 2010 at 3:31 PM, Sebastien Loriot (GeometryFactory) <sloriot.ml <http://sloriot.ml>@gmail.com <http://gmail.com>> wrote:

   Did you define a copy constructor and forget to copy the object?
   I think in your case, you should use a boost::Variant as the number of
   possible types is only 2.



   Costas Tsirogiannis wrote:


       Here's scraps of code that are indicative of the situation:

       * In the augmented halfedge class I store a CGAL::Object that
       contains
       * a handle, it could be either a face handle or an edge stored
       in it:

       Object  _corresponding_triangulation_object;

       * And the member functions that make use of it are:

        bool overlaps_with_triangulation_edge(void)
        { bool temp = _corresponding_triangulation_object.template
       is<Triangulation_face_handle>();
         return !temp; }
        void set_corresponding_triangulation_object( Object &obj )
        { _corresponding_triangulation_object = obj; }

        template< typename Triangulation_item >
        void set_corresponding_triangulation_object( Triangulation_item
       &t_item )
        { _corresponding_triangulation_object =
       Construct_object()(t_item); }

        Object& corresponding_triangulation_object(void)
        { return _corresponding_triangulation_object; }  
       * So let's say that at some point some function "A"  is called
       where it does this:

       Halfedge_handle current_ph;

       **** do something with current_ph ****

        Halfedge_handle   target_ph, old_ph;

       target_ph = fnwk.surface_polyhedron().split_edge( current_ph );
       target_ph->vertex()->point() = p;

        old_ph = target_ph->next();
        target_ph->set_corresponding_triangulation_object(current_ph->corresponding_triangulation_object());
                         CGAL_assertion(target_ph->overlaps_with_triangulation_edge());
        target_ph->opposite()->set_corresponding_triangulation_object(current_ph->opposite()->corresponding_triangulation_object());
        CGAL_assertion(target_ph->opposite()->overlaps_with_triangulation_edge());
        old_ph->opposite()->set_corresponding_triangulation_object(current_ph->opposite()->corresponding_triangulation_object());

       * Up to here everything is executed ok. But in the following
       code, after the execution
       *of "A" is done, when I traverse the polyhedron face that
       contains the above halfedges I get *segmentation faults  either
       in the std::cout line or in the line where
       *->overlaps_with_triangulation_edge() is called.


       Halfedge_handle other_ph = ..... ;
       Triangulation_edge entry_te = ..... ;
       Triangulation_edge current_te = entry_te;

       while( !(other_ph->overlaps_with_triangulation_edge()) ||
       current_te == entry_te )
        {
           std::cout << " other_ph->vertex : "<<
        other_ph->vertex()->point() << std::endl;

          other_ph = other_ph->next();

          if(other_ph->overlaps_with_triangulation_edge())
            CGAL::assign(current_te,
       other_ph->corresponding_triangulation_object() );
        }

        I think there is no problem with accessing the vertex point,
       the memory error
       has to do with the triangulation handles stored as objects in
       the halfedges.

       thanks

       Constantinos




       On Tue, Jul 6, 2010 at 7:48 AM, Sebastien Loriot
       (GeometryFactory) <sloriot.ml <http://sloriot.ml>
       <http://sloriot.ml>@gmail.com <http://gmail.com>
       <http://gmail.com>> wrote:

          Costas Tsirogiannis wrote:

              Greetings,

              I have a problem with run-time errors coming from an
       unorthodox
              use of handles:

               I make use of a triangulation and of an augmented
       polyhedron_3
              object. This augmented polyhedron
              is a refinement of the surface represented by the
       triangulation
              : as some algorithm goes on, new edges
              are added on what used to be the triangular faces. It is
              important that the halfedges,faces and vertices
              on the polyhedron that originate from features of the
              triangulation should point to the corresponding triangulation
              features.  Thus each feature stores a handle of the original
              triangulation object: a polyhedron vertex stores a handle
              to the original triangulation vertex of the same
       coordinates, a
              halfedge stores a handle to the triangulation edge or
              face on which it lies etc.
               When a feature is refined eg a halfedge is split, these
       stored
              handles of triangulation features are copied to
              the newly created features. And then segmentation faults
       appear.

          What do you use to split halfedges ? (the underlying question
       being how
          your handles are set)


              Specifically, things go wrong when there is an attempt
              to access the handle member object of the new feature
       outside of
              the function that created the feature (and copied the
              handle object to it).  Any ideas for what could fix this?

              thanks

              Constantinos



          --     You are currently subscribed to cgal-discuss.
          To unsubscribe or access the archives, go to
          https://lists-sop.inria.fr/wws/info/cgal-discuss




   --     You are currently subscribed to cgal-discuss.
   To unsubscribe or access the archives, go to
   https://lists-sop.inria.fr/wws/info/cgal-discuss




--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss





Archive powered by MHonArc 2.6.16.

Top of Page