Author Topic: Zoom::flipWithZoom can run out of memory (or it's a bpp=32 issue)  (Read 2561 times)

Offline Skybuck

  • Colonel
  • ****
  • Posts: 223
    • View Profile
Zoom::flipWithZoom can run out of memory.

It's the scalers

int Zoom::_zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)

down in the code it does this:

   /*
   * Allocate memory for row increments
   */
   if ((sax = (Uint32 *) realloc(sax, (dst->w + 1) * sizeof(Uint32))) == NULL) {
      sax = 0;
      return (-1);
   }
   if ((say = (Uint32 *) realloc(say, (dst->h + 1) * sizeof(Uint32))) == NULL) {
      say = 0;
      //free(sax);
      return (-1);
   }

I find this kind of weird and sloppy. Personally I would move this code out of there and to a special initialization function for these scalers and then call it one time or at least when display is reset, so that the memory allocation is more near each other, and not somewhere in a scaler function. 

This makes it easier for the programmer to understand where and why the memory went out of memory... now it feels more like a scalar bug... while in reality it's an out of memory bug. I think out of memory bugs should be handled seperately from "computational" code... (as much as possible)

It's also possible that this scalar code fails to handle bpp=32. (32 bits per pixel).

Perhaps these scalers were only written with 8 bit in mind ? Or it does 32 bit allocation wrong ? Or it's some kind of weird memory alignment problem ?
« Last Edit: June 03, 2022, 02:39:33 am by Skybuck »