0

I have a problem when trying to tesselate a polygon using GLU. The vertex callback always calls back with the last vertex defined by gluTessVertex. It seems as though the values stored in GLdouble v[3] are getting GC'd in each iteration of the for loop. How can I store each GLdouble v[3] so it does not get GC'd?

for(int i = 0; i < vtxcnt; i++)
{
    float lon = dbls[i * 2];
    float lat = dbls[(i * 2)+1];
    GLdouble v[3] = {lon, lat, 0.0f};
    gluTessVertex(tess, v, v);
}

* EDIT: This seems to fix the problem... *

GLdouble *vtxs = new GLdouble[vtxcnt * 3];

for(int i = 0; i < vtxcnt; i++)
{
    lon = dbls[i * 2];
    lat = dbls[(i * 2)+1];

    vtxs[(i * 3) + 0] = (double)lon;
    vtxs[(i * 3) + 1] = (double)lat;
    vtxs[(i * 3) + 2] = (double)0;
    gluTessVertex(tess, &vtxs[(i * 3) + 0], &vtxs[(i * 3) + 0]);
}
1
  • 3
    Standard C++ doesn't have a garbage collector at all. Commented Sep 22, 2012 at 16:15

1 Answer 1

1

gluTessVertex only stores the vertex pointer. The pointer must stay valid until the tesselation is performed. This is not the case in your code, so it fails.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.