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?
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.
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?
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 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.