Hi,
i have a large file which holds a lot of coordinates of lines. These line form a map. In my main program I have a boolean array which keep track of the lines which need to be highlighted. I'm using OpgenGL for displaying the map, following the lighthouse3d tutorial.
The display list is created as follows:
Code:
GLuint createDL() {
GLuint mapDL;
mapDL = glGenLists(1); // Create the id for the list
glNewList(mapDL,GL_COMPILE); // start list
GLpaintShapeFile();
renderMap(); // call the function that contains
// the rendering commands
glEndList(); // endList
return(mapDL);
}
The function GLpaintShapeFile reads the file with lines and calss the function which draws those lines:
Code:
void GLpaintShapeFile(){
for(int i = 0; i < nEntities; i++ )
{
SHPObject *psShape;
psShape = SHPReadObject( hSHP, i );
//first paint all the non-highlighted parts
GLpaintShape(psShape, psShape->nVertices, i, 1);
SHPDestroyObject( psShape );
}
for(i = 0; i < nEntities; i++ )
{
SHPObject *psShape;
psShape = SHPReadObject( hSHP, i );
//then, paint all the highlighted parts
GLpaintShape(psShape, psShape->nVertices, i, 2);
SHPDestroyObject( psShape );
}
The function which actually draws them is:
Code:
void GLpaintShape(SHPObject *psShape, int n, int i, int k){
if(n>0){
if(psShape->nSHPType==3){
if ((highlight[i]==false)&&(k==1)){
glColor3f(1,1,1);
for(int j=1;j<n;j++){
glBegin(GL_LINES);
glVertex2f(psShape->padfX[j-1],psShape->padfY[j-1]);
glVertex2f(psShape->padfX[j],psShape->padfY[j]);
}
}
else if((highlight[i]==true)&&(k==2)){
glColor3f(0,1,0);
for(int j=1;j<n;j++){
glBegin(GL_LINES);
glVertex2f(psShape->padfX[j-1],psShape->padfY[j-1]);
glVertex2f(psShape->padfX[j],psShape->padfY[j]);
}
}
}
}
}
The problem is: after the function GLpaintShapeFile() is called, there is about 10 MB of memory which is being used but never freed. So everytime there is a change and the map needs to be changed, my program uses 10 MB extra. I know I probably have to free memory somewhere (from the outdated map) before drawing the new map, but where? What has to be deleted?
I hope someone can help me.
P.S. Sorry for the large amount of code, but I'm using non-standard object. Therefor I've included it to make it more clear. I hope.