The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Texture loading function keeps returning texture into RAM
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
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;
}
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
Oh, the title is a bit misleading, the SDL_Texture* texture will receive the returned texture, but newTexture will stay floating in RAM.
luca00555


Joined: 04 Jan 2015
Posts: 33
Location: The Netherlands
Instead of deleting itself.

The edit button really sould be enabled....
Texture loading function keeps returning texture into RAM
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
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:
Quote:
Instead of deleting itself.

The edit button really sould be enabled....


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Texture loading function keeps returning texture into RAM
Jared Maddox
Guest

Quote:
Date: Sat, 28 Feb 2015 23:31:24 +0000
From: "luca00555"
To:
Subject: Re: [SDL] Texture loading function keeps returning texture
into RAM
Message-ID:
Content-Type: text/plain; charset="iso-8859-1"


Quote:
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".
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org