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: 42
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

KGL - textures and memory managment

Post by 111 »

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 67 times
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: KGL - textures and memory managment

Post by Chilly Willy »

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: 42
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

Re: KGL - textures and memory managment

Post by 111 »

...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 thanked: 0
Been thanked: 2 times

Re: KGL - textures and memory managment

Post by Chilly Willy »

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