SDL_gfx - rotozoomSurfaceXY (memory leak?)

Started by
0 comments, last by archaos90 15 years ago
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. :)
Advertisement
shameless bump

This topic is closed to new replies.

Advertisement