I spend a whole day, trying to figure out what is wrong.
There was a memory leak found , but a really strange one, because it didn't appear all the times, and the memory addresses were different all the time:
Detected memory leaks!
Dumping objects ->
{634} normal block at 0x0B141FF8, 126720 bytes long.
Data: <@,%>*#:1,C:5E769> 40 2C 25 3E 2A 23 3A 31 2C 43 3A 35 45 37 36 39
{588} normal block at 0x0B123010, 126720 bytes long.
Data: <@,%>*#:1,C:5E769> 40 2C 25 3E 2A 23 3A 31 2C 43 3A 35 45 37 36 39
{552} normal block at 0x0B104028, 126720 bytes long.
Data: <@,%>*#:1,C:5E769> 40 2C 25 3E 2A 23 3A 31 2C 43 3A 35 45 37 36 39
I am not sure if there is any such place somewhere in the code.
This memory leak is starting to appear when I am loading lots of textures, about 90, and some times number of memory leaks is different, probably depending on the order of loading or the texture names.
Later on I found that it was somehow related to my anisotropic extension loading code, and later I found it was actually in the class for loading extension names, that read all the OpenGL extension strings and saved them in a list.
Some thing like this:
long i = 0;
long k = 0;
char c = 'z';
long size = strlen( _extRaw );
char temp[128];
memset(temp,0,128);
while(i < size )
{
c = _extRaw[i++];
//insert line
if( c == ' ')
{
AddListExt( temp );
//new line
k = 0;
memset(temp,0,128);
}
else
{
temp[k++] = c;
}
}
extRaw is OpenGL raw value of extensions obtained by calling glGetString(GL_EXTENSIONS); The actual memory leak seam to be happening in the AddListExt function, which allocates the string and adds it to the list:
int length = strlen(extName) + 1;
_name = (char*)malloc( length );
sprintf(_name , "%s", extName );
This is where it happens. The strangest part is that the memory leak message is hardly related to the memory leak itself, because the string is not even close to that size. The leak also happens if the input string is larger then 75 chars. Strange.
But I think the real problem is in another part of the code. My extension manager loads extensions only if somewhere in the code it is requested, then it calls glGetString(GL_EXTENSIONS);. For example if I am going to apply filtering, I should do it when creating texture, this is where the anisotropic extension is loaded first time, maybe somehow it causes this problem, I am not sure.
I moved my extension loading code to the the video class, so the extensions are loaded after the first video mode set, the problem solved. This was one of the most strangest bugs I have ever experienced.