Jump to content
  • Advertisement
Sign in to follow this  
nunosantos

OpenGL Clearing memory allocated for textures

This topic is 4060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a opengl app which loades images and displays them in a 3D way. I getting a big memory consumption. I think i'm doing something wrong. Is there any way of forcing garbage collection? This is the way i'm doing the image loading (i'm using TAO framwork) <code> private bool LoadImages() { try { images = new int[2]; Il.ilGenImages(2, imageIds); // Generate Image Ids for (int i = 0; i < 2; i++) { Console.WriteLine("Loading images!"); Il.ilBindImage(imageIds); // Bind Image Id to Be Current if (!Il.ilLoadImage(imagesName)) { Il.ilDeleteImages(2, imageIds); return false; } Console.WriteLine( "Image name: " + imagesName + " Width: " + Il.ilGetInteger(Il.IL_IMAGE_WIDTH) + " Height: " + Il.ilGetInteger(Il.IL_IMAGE_HEIGHT)); images = Ilut.ilutGLBindTexImage(); if (Il.ilGetError() != 0) { Console.WriteLine("Image loading error report: " + Ilu.iluErrorString(Il.ilGetError())); Il.ilDeleteImages(2, imageIds); return false; } } } catch (AccessViolationException) { Console.WriteLine("Access Violation Exception: Estourou neste metodo!"); } return true; } </code> Thx, Nuno

Share this post


Link to post
Share on other sites
Advertisement
Are any of the objects implementing IDisposable. If so, you need to call their dispose method to release the memory. Otherwise I'm not sure.

Share this post


Link to post
Share on other sites
i found the problem.

do you see in the code above?

I'm using the devil's function

images = Ilut.ilutGLBindTexImage();

which is creating a new texture everytime it's called.

i call the function in the reply above a lot of times!

i need to find a way to reuse the same texture id instead of creating a new one.

if i use the function

Ilut.ilutGLTexImage();

the memory problems disappears. However, i not managing to load the image to the texture i want.

I though that the functions parameter (level) would be to tell which texture i want to map the image into.

Can you help me out?

Thx,

Nuno

Share this post


Link to post
Share on other sites
Hi,

Someone has helped me finding a solution:

Here is my actual load function. Maybe that will help someone in the future:

C# code using tao framwork:

private bool LoadImages()
{
Console.WriteLine("Loading images!");

try
{
Il.ilGenImages(2, imageIds); // Generate Image Ids

if (images[0] != -1) // Free up old textures
{
Gl.glDeleteTextures(2, images);
images[0] = -1;
images[1] = -1;
}

for (int i = 0; i < 2; i++)
{
Il.ilBindImage(imageIds); // Bind Image Id to Be Current
if (!Il.ilLoadImage(imagesName))
{
Il.ilDeleteImages(2, imageIds);
return false;
}

Console.WriteLine(
"Image name: " + imagesName +
" Width: " + Il.ilGetInteger(Il.IL_IMAGE_WIDTH) +
" Height: " + Il.ilGetInteger(Il.IL_IMAGE_HEIGHT));

images = Ilut.ilutGLBindTexImage();

if (Il.ilGetError() != 0)
{
Console.WriteLine("Image loading error report: " + Ilu.iluErrorString(Il.ilGetError()));
Il.ilDeleteImages(2, imageIds);
return false;
}

Il.ilDeleteImages(2, imageIds); // Should not need the ilImage since there is now an OpenGL Image
}
}
catch (AccessViolationException error)
{
Console.WriteLine("Access Violation Exception: " + error.Message);
}

return true;
}


Best regards,

Nuno

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!