Why doesn't this work?

Posted by user146780 on Stack Overflow See other posts from Stack Overflow or by user146780
Published on 2010-05-25T00:43:38Z Indexed on 2010/05/25 0:51 UTC
Read the original article Hit count: 272

Filed under:
|
|

I'v tried to solve a memory leak in the GLU callback by creating a global variable but now it dos not draw anything:

GLdouble *gluptr = NULL;

void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4],
                              GLfloat weight[4], GLdouble **dataOut)
{
    GLdouble *vertex;
    if(gluptr == NULL)
    {
        gluptr = (GLdouble *) malloc(6 * sizeof(GLdouble));
    }
    vertex = (GLdouble*)gluptr;
    vertex[0] = coords[0];
    vertex[1] = coords[1];
    vertex[2] = coords[2];


    for (int i = 3; i < 6; i++)
    {

        vertex[i] = weight[0] * vertex_data[0][i] +
            weight[1] * vertex_data[0][i] +
            weight[2] * vertex_data[0][i] +
            weight[3] * vertex_data[0][i];
    }


    *dataOut = vertex;


}

basically instead of doing malloc each time in the loop (thus the memory leak) im using a global pointer, but this doesn't work (drawing to the screen). Why would using malloc to a pointer created in the function work any different than a global variable?

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about c