Results 1 to 3 of 3

Thread: Heap Corruption occurring in gluTessVertex - Please help

  1. #1
    Member Newbie
    Join Date
    Jun 2006
    Posts
    31

    Heap Corruption occurring in gluTessVertex - Please help

    I am trying to tesselate the interior of an irregular polygon with the following C++/Psuedo code:

    I declare the following function:

    vertexCallback(GLdouble *vertex)
    {
    const GLdouble *pointer;

    pointer = (GLdouble *) vertex;
    glColor3dv(pointer+3);
    glVertex3dv(vertex);
    }

    All the others callbacks (combine, begin, end, error) are declared as well.

    I also declare the following struct:

    typedef struct
    {
    double x, y, z;
    } coordinate;


    I created a vector as follows:

    vector <coordinate> TessPath;

    To add a vertex, I do the following:

    coordinate loc;
    loc.x = x;
    loc.y = y;
    loc.z = 0.0;

    path.push_back(loc);
    gluTessVertex(tess,reinterpret_cast<double*>(&path[path.size() - 1]),reinterpret_cast<void *>(&path[path.size() - 1]));

    The Tessellations are really messed up, going all over the screen.

    When I run the program under valgrind, it gives the following:
    ==12310== Invalid read of size 4
    ==12310== at 0x410CD29: (within /usr/lib/libGL.so.1.2)
    ==12310== by 0x40F3C79: glVertex3dv (in /usr/lib/libGL.so.1.2)
    ==12310== by 0x408103E: (within /usr/lib/libGLU.so.1.3.060402)
    ==12310== by 0x40809EE: __gl_renderMesh (in /usr/lib/libGLU.so.1.3.060402)
    ==12310== by 0x40844C3: gluTessEndPolygon (in /usr/lib/libGLU.so.1.3.060402)
    ==12310== by 0x8067E28: Symbol::render() (in /home/fordj/Desktop/mlp/a.out)


    What in the world am I doing wrong??? I have corrupted the heap somehow. When I comment out all of the Tessellation code, it runs beautifully sans filled interiors and valgrind has no complaints. The gluTessVertex, which in turn is calling glVertex3dv is the problem I believe.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: Heap Corruption occurring in gluTessVertex - Please help

    It is likely that your problem is using of push_back() on vector container. Vector container allocates some memory to store its objects. When all that memory is filled by elements, the next call to push_back() will reallocate memory with new bigger size and copy old content here. The result of this is that addresses of all elements within the vector may change. Because of this, some pointers you passed to the gluTessVertex are no longer valid when gluTessEndPolygon is not called.

  3. #3
    Member Newbie
    Join Date
    Jun 2006
    Posts
    31

    Re: Heap Corruption occurring in gluTessVertex - Please help

    OF COURSE!!!!! Thank you!! I used TessPath.resize(10000) before adding any coordinates to see if it would work and it did. Now i just have to figure out the correct value to replace the 10000 for each contour.

Similar Threads

  1. Replies: 1
    Last Post: 10-24-2011, 01:16 PM
  2. gluTesselator Heap Corruption
    By blufiro in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-17-2009, 01:12 AM
  3. Replies: 4
    Last Post: 01-02-2009, 12:40 PM
  4. Heap Corruption occurring in gluTessVertex - Please help
    By Jorufo in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-01-2006, 07:25 PM
  5. Problem with eglSwapBuffers and heap corruption
    By GreatApe in forum OpenGL ES
    Replies: 2
    Last Post: 05-25-2005, 12:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean