KGL - textures and memory managment

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
111
DCEmu Junior
DCEmu Junior
Posts: 37
Joined: Thu Jul 07, 2016 7:11 pm
Has liked: 0
Been liked: 0

KGL - textures and memory managment

Post by 111 » Thu Jul 28, 2016 6:43 am

While browsing example programs, I noticed that after loading textures using glTextureLoadPVR() there was no code to unload them. I thought it was like this simply because it was not needed for such small demos.

So I tried to use glDeleteTextures(), but it does not seem to work at all.
And the question is, what should I do instead?

For more info, see attached example project.
Attachments
skybox.zip
(467.65 KiB) Downloaded 41 times
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

Re: KGL - textures and memory managment

Post by Chilly Willy » Thu Jul 28, 2016 12:06 pm

Well, other than not simply doing

Code: Select all

    glDeleteTextures(6, g_Texture);
you're not closing the texture file after loading it. So you fail on the next pass because it can't open an already opened file.
111
DCEmu Junior
DCEmu Junior
Posts: 37
Joined: Thu Jul 07, 2016 7:11 pm
Has liked: 0
Been liked: 0

Re: KGL - textures and memory managment

Post by 111 » Thu Jul 28, 2016 1:33 pm

...indeed, fixing it took just as much as adding

Code: Select all

fclose(tex);
to the end of glTextureLoadPVR()

Thank you so much! You're a life saver.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has liked: 0
Been liked: 2 times

Re: KGL - textures and memory managment

Post by Chilly Willy » Thu Jul 28, 2016 3:31 pm

You would have run into the fclose problem eventually. As you added more textures, you would have run out of file handles and fopen would start failing. Anywho, this is a good example of the necessity of adding error messages after calls like fopen.
Post Reply