Jump to content
  • Advertisement
Sign in to follow this  
archaos90

SDL_gfx - rotozoomSurfaceXY (memory leak?)

This topic is 3558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I've been sitting with this memory leak for some time now. I've located the source of the memory leak but I can't figure out what's causing it. The leak occurs inside the for-loop. I am suspicious of that the rotozoomSurfaceXY() function (it's a SDL_gfx function) doesn't free surfaces properly. Here's the code that is faulty:
void EasySDL_Sprite::setAngle(double value)
{
     if(value >= 360.0)
     {
          return;
     }     
     angle = value;  
           
     for(int i = 0; i < frames.size(); i++)
     {                   
         SDL_Surface *new_sur = SDL_CreateRGBSurface(
                           core->gfx->getSettings().memory_type | SDL_SRCALPHA,         
                           frames->w, 
                           frames->h, 
                           core->gfx->getSettings().bitsperpixel, 0, 0, 0, 0);                 
         new_sur = rotozoomSurfaceXY(frames, angle, 1.0, 1.0, 0);
         SDL_SetColorKey(new_sur, 
                         SDL_SRCCOLORKEY, 
                         SDL_MapRGB(new_sur->format, 
                                    trans_color.r, 
                                    trans_color.g, 
                                    trans_color.b));                  
         replaceSprite(i, new_sur);   
      }                                 
}
All called functions except for replaceSprite are the SDL and SDL_gfx ones and are not customized (e.g their sources are unmodified). Just telling you so you don't have to bother to ask. This replaceSprite() function WORKS, but you might want the source for it anyway. Who knows? It might be faulty even if I say it's not.
void EasySDL_Sprite::replaceSprite(int id, SDL_Surface *surface)
{
           SDL_Surface *surface2 = SDL_DisplayFormat(surface);
           SDL_SetColorKey(surface2, 
                           SDL_SRCCOLORKEY, 
                           SDL_MapRGB(surface2->format, 
                                      trans_color.r, 
                                      trans_color.g, 
                                      trans_color.b));
           SDL_FreeSurface(surface);
           surface = NULL;
           geometry.w = surface2->w;
           geometry.h = surface2->h;           
           SDL_FreeSurface(frames[id]);
           frames[id] = NULL;
           frames[id] = surface2;
}
Also, EasySDL_Sprite is a class that is part of a library I am making. Name sucks but who cars about names, huh? =) The library is solely for making it easier for me to make games and for my future big application that will be a complete game generator that'll use this library a lot. But we'll see about that, won't we? I tend to not finish my projects, haha. Back to topic. Help would be appreciated. :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!