Beginner's Question About SDL Tutorial

I am using the very useful lazyfoo SDL tutorials. I have a question about tutorial number 7 (http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php)

A texture and a surface are declared. loadedSurface is not returned by the function and so its memory is freed. However since newTexture is returned by the function, its memory cannot be freed. Is this a problem? If this is not a problem why bother to free the memory of loadedSurface?

Thank you

I’m not very familiar with these tutorials, but you need to free any
texture you create with SDL_DestroyTexture(), just as you freed the
surface. It looks like the function in question is only used to fill a
global pointer, gTexture, which is actually freed by SDL_DestroyTexture()
in the close() function. However, in a real scenario, you might have
multiple textures and each will need to be destroyed when you’re done with
them to prevent resource leaks.

Hope this helps.

CBOn 9 December 2015 at 05:10, Ironic wrote:

I am using the very useful lazyfoo SDL tutorials. I have a question about tutorial
number 7
http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php

A texture and a surface are declared. loadedSurface is not returned by the
function and so its memory is freed. However since newTexture is returned
by the function, its memory cannot be freed. Is this a problem? If this is
not a problem why bother to free the memory of loadedSurface?

Thank you


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The Texture will end up in gTexture which is global and freed in close()On 12/09/2015 11:10 AM, Ironic wrote:

I am using the very useful lazyfoo SDL tutorials. I have a question
about tutorial number 7
http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php

A texture and a surface are declared. loadedSurface is not returned by
the function and so its memory is freed. However since newTexture is
returned by the function, its memory cannot be freed. Is this a problem?
If this is not a problem why bother to free the memory of loadedSurface?

Thank you


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thank you for your replies. They were helpful. I tried to rewrite the tutorial so that it would be class with no global variables which is why I missed it.