Texture loading function keeps returning texture into RAM

When loading a texture with this onto a SDL_Texture* texture, the function keeps the texture that will be returned floating around in RAM.
I have no idea how I can change this, because my program is multithreaded too.
Anyone who has an idea how to fix this?

Code:
SDL_Texture* loadTexture(std::string path)
{
SDL_Texture* newTexture = NULL;
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if(loadedSurface == NULL)
{
printf(“Unable to load image %s! SDL_image Error: %s\n”, path.c_str(), IMG_GetError());
}
else
{
SDL_SemWait(semRendererLock);
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
SDL_SemPost(semRendererLock);
if(newTexture == NULL)
{
printf(“Unable to create texture from %s! SDL Error: %s\n”, path.c_str(), SDL_GetError());
}
SDL_FreeSurface(loadedSurface);
}
return newTexture;
}

Oh, the title is a bit misleading, the SDL_Texture* texture will receive the returned texture, but newTexture will stay floating in RAM.

Instead of deleting itself.

The edit button really sould be enabled…

I’m sort of confused; newTexture appears to be the SDL_Texture* that you
are returning, so it wouldn’t make sense that you would free it until you
are done with it. It looks like loadedSurface is being dealt with
properly. With that in mind, I have no idea which variable isn’t being
freed that you expect to be freed.On Sat, Feb 28, 2015 at 6:31 PM, luca00555 wrote:

Instead of deleting itself.

The edit button really sould be enabled…


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

    into RAM

Message-ID: <1425166284.m2f.47079 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

The edit button really sould be enabled…

Obviously you wrote the original message on the forum. I, however, am
reading it on the automatically synchronized mailinglist. Thus, the
edit button CAN’T be enabled, because email doesn’t support editing
after you’ve hit “send”.> Date: Sat, 28 Feb 2015 23:31:24 +0000

From: “luca00555”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Texture loading function keeps returning texture