SDL_BlitSurface causes memory leak on MacOS X

When I use SDL_BlitSurface on Mac OS X it seems to cause a memory leak, it’s probably in some way related to the way I’m using Blit but anyway I needed a quick hack to get round the problem, performance is not really an issue so I just wrote a function to write the points to the screen one by one:

There are a bunch of things this version doesn’t do that SDL_BlitSurface does, so beware. It ignores src_rec (just like SDL_BlitSurface would if it were NULL), and it does no conversion to insure source and dest are the same format (so you’ll have to convert the surfaces first).

void SlowBlitSurface(SDL_Surface *source,SDL_Rect *src_rec,SDL_Surface *dest,SDL_Rect *dest_rec) {

  int sbpp = source->format->BytesPerPixel;
  int dbpp = dest->format->BytesPerPixel;
  for(size_t x=0;x<source->w;x++) {
    for(size_t y=0;y<source->h;y++) {
      Uint8 *p = (Uint8 *)source->pixels + (((y * source->w) + x) * sbpp);
      Uint32 pval = *(Uint32 *) p;
      Uint8 *d = (Uint8 *)dest->pixels   + ((((dest_rec->y+y) * (dest->w)) + (dest_rec->x+x)) * dbpp);
      *((Uint32 *) d) = pval;
For blog updates and more follow me on twitter.