Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:30:47+00:00 2026-06-10T19:30:47+00:00

I’m using a GLUtesselator to fill some nonconvex polygons. It worked quite well but

  • 0

I’m using a GLUtesselator to fill some nonconvex polygons.

It worked quite well but with some polygons it complained that it needed a combine function so I’ve provided a very simple GLU_TESS_COMBINE callback, which allocates a new vertex and just copies the coords (it’s 2D with solid colors, so I don’t need to interpolate RGB values or anything):

void CALLBACK tessCombine( GLdouble coords[3], GLdouble * vertex_data[4], GLfloat weight[4], GLdouble **outData )
{
    GLdouble *vertex = new GLdouble[3];
    vertex[0] = coords[0];
    vertex[1] = coords[1];
    vertex[2] = coords[2];
    *outData = vertex;
}

Now everything is rendered as expected, but it obviously leaks memory. The docs say:

Allocate another vertex, […] Free the memory sometime after
calling gluTessEndPolygon.

But in all the examples I’ve found, they don’t show how to handle the memory. The callbacks are free functions and there’s no way to free the memory allocated there, is there?

The only way I can think of is to store them somewhere and then delete them myself. Is this the correct way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:30:49+00:00Added an answer on June 10, 2026 at 7:30 pm

    Take a look into this OpenGL Tessellation tutorial.

    The point is not to allocate any memory in the callback (otherwise you are going to get a memory leak). Instead, you should copy vertex data to the memory location in the callback (as it is done in the example). From where you copy vertex data, it is up to you.

    This is how the callback function looks in their example :

    void CALLBACK tessCombineCB(const GLdouble newVertex[3], const GLdouble *neighborVertex[4],
                                const GLfloat neighborWeight[4], GLdouble **outData)
    {
        // copy new intersect vertex to local array
        // Because newVertex is temporal and cannot be hold by tessellator until next
        // vertex callback called, it must be copied to the safe place in the app.
        // Once gluTessEndPolygon() called, then you can safly deallocate the array.
        vertices[vertexIndex][0] = newVertex[0];
        vertices[vertexIndex][1] = newVertex[1];
        vertices[vertexIndex][2] = newVertex[2];
    
        // compute vertex color with given weights and colors of 4 neighbors
        // the neighborVertex[4] must hold required info, in this case, color.
        // neighborVertex was actually the third param of gluTessVertex() and is
        // passed into here to compute the color of the intersect vertex.
        vertices[vertexIndex][3] = neighborWeight[0] * neighborVertex[0][3] +   // red
                                   neighborWeight[1] * neighborVertex[1][3] +
                                   neighborWeight[2] * neighborVertex[2][3] +
                                   neighborWeight[3] * neighborVertex[3][3];
        vertices[vertexIndex][4] = neighborWeight[0] * neighborVertex[0][4] +   // green
                                   neighborWeight[1] * neighborVertex[1][4] +
                                   neighborWeight[2] * neighborVertex[2][4] +
                                   neighborWeight[3] * neighborVertex[3][4];
        vertices[vertexIndex][5] = neighborWeight[0] * neighborVertex[0][5] +   // blue
                                   neighborWeight[1] * neighborVertex[1][5] +
                                   neighborWeight[2] * neighborVertex[2][5] +
                                   neighborWeight[3] * neighborVertex[3][5];
    
    
        // return output data (vertex coords and others)
        *outData = vertices[vertexIndex];   // assign the address of new intersect vertex
    
        ++vertexIndex;  // increase index for next vertex
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.