Segmentation Fault with OpenGL tesselation

Hello to all. I have a problem that I can in no way understand. I wrote a program in C + + and OpenGL using MinGW, which displays a map in 2D.
The following is a function that does the fault occur, ie when executes the statement gluTessEndPolygon (tobj) gives me segmentation fault:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// render each block as a polygon extruded into Z
void BlockGroup::BuildDisplayList()
{
  static GLUtesselator *tobj = NULL;

  if( ! mod.world->IsGUI() )
    return;

  std::vector<std::vector<GLdouble> > contours;

  FOR_EACH( blk, blocks )
  {
        std::vector<GLdouble> verts;
        FOR_EACH( it, blk->pts )
        {
         verts.push_back( it->x ); 
         verts.push_back( it->y ); 
         verts.push_back( blk->local_z.max );
        }
        contours.push_back( verts );
  }

  if( displaylist == 0 )
  {
        CalcSize(); // todo: is this redundant? count calls per model
                    // to figure this out.

        displaylist = glGenLists(1);
        assert(displaylist !=0 );

        // Stage polygons need not be convex, so we have to
        // tesselate them for rendering in OpenGL.
        tobj = gluNewTess();
        assert(tobj != NULL);

        //GG: inizio
        gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (CALLBACK*) ()) 
                                                                &glVertex3dv);
        gluTessCallback(tobj, GLU_TESS_EDGE_FLAG, (GLvoid (CALLBACK*) ()) 
                                                                 &glEdgeFlag);
        gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid (CALLBACK*) ()) &glBegin);
        gluTessCallback(tobj, GLU_TESS_END, (GLvoid (CALLBACK*) ()) &glEnd);

        // these use the standard GL calls
        gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (CALLBACK*) ()) 
                                                               &errorCallback);
        gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid (CALLBACK*) ()) 
                                                             &combineCallback);
        //GG: fine
  }

  glNewList( displaylist, GL_COMPILE );

  Gl::pose_shift( mod.GetGeom().pose );

  // draw filled polys
  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
  glEnable(GL_POLYGON_OFFSET_FILL);
  glPolygonOffset(0.5, 0.5);

  mod.PushColor( mod.color );

  // primo contorno
  gluTessBeginPolygon(tobj, NULL);

  FOR_EACH( contour, contours )
  {
        gluTessBeginContour(tobj);

        //for( size_t v = 0; v < contours.size(); v+=3 )
        for( size_t v = 0; v < contour->size(); v += 3 )
            gluTessVertex(tobj, &(*contour)[v], &(*contour)[v]);

        gluTessEndContour(tobj);
  }

  gluTessEndPolygon(tobj);
  ...
}

contours is a list of vectors of the following type:
 
std::vector<std::vector<GLdouble> > contours;

I report also:
1
2
3
#define VAR(V, init) __typeof(init) V=(init)
#define FOR_EACH(I,C) for(VAR(I, (C).begin()), ite = (C).end(); (I) != ite;
                                                                       ++(I))

I tried to use the debug and have come to the message of Segmentation Fault on education above. Now I do not know what to do.
Can you help me, I seem to go crazy with this code.
anyone can help me?
I found where is the error. The following two instructions
gluTessBeginPolygon(tobj, NULL); gluTessEndPolygon(tobj);
should be placed here:
1
2
3
4
5
6
7
8
9
10
11
12
  FOR_EACH( contour, contours )
  {
     gluTessBeginPolygon(tobj, NULL);
        gluTessBeginContour(tobj);

        //for( size_t v = 0; v < contours.size(); v+=3 )
        for( size_t v = 0; v < contour->size(); v += 3 )
            gluTessVertex(tobj, &(*contour)[v], &(*contour)[v]);

        gluTessEndContour(tobj);
     gluTessEndPolygon(tobj);
  }
Topic archived. No new replies allowed.