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?