Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
authorSam Lantinga <slouken@libsdl.org>
Sat, 01 Feb 2003 20:33:59 +0000
changeset 5921970e458070d
parent 591 9c9598e4b904
child 593 0136d21b7764
Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
src/video/quartz/SDL_QuartzWM.m
     1.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sat Feb 01 20:32:44 2003 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sat Feb 01 20:33:59 2003 +0000
     1.3 @@ -227,8 +227,7 @@
     1.4      NSBitmapImageRep *imgrep;
     1.5      NSImage *img;
     1.6      SDL_Surface *mergedSurface;
     1.7 -    Uint8 *surfPtr;
     1.8 -    int i,j,masksize;
     1.9 +    int i,j;
    1.10      NSAutoreleasePool *pool;
    1.11      SDL_Rect rrect;
    1.12      NSSize imgSize = {icon->w, icon->h};
    1.13 @@ -244,18 +243,34 @@
    1.14          goto freePool;
    1.15      }
    1.16      
    1.17 +    if (mergedSurface->pitch != 
    1.18 +        mergedSurface->format->BytesPerPixel * mergedSurface->w) {
    1.19 +        SDL_SetError ("merged surface has wrong format");
    1.20 +        SDL_FreeSurface (mergedSurface);
    1.21 +        goto freePool;
    1.22 +    }
    1.23 +    
    1.24      if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
    1.25          NSLog(@"Error blitting to mergedSurface");
    1.26          goto freePool;
    1.27      }
    1.28      
    1.29      if (mask) {
    1.30 -        masksize=icon->w*icon->h;
    1.31 -        surfPtr = (Uint8 *)mergedSurface->pixels;
    1.32 -        #define ALPHASHIFT 3
    1.33 -        for (i=0;i<masksize;i+=8)
    1.34 -            for (j=0;j<8;j++) 
    1.35 -                surfPtr[ALPHASHIFT+((i+j)<<2)]=(mask[i>>3]&(1<<(7-j)))?0xFF:0x00;
    1.36 +
    1.37 +        Uint32 *pixels = mergedSurface->pixels;
    1.38 +        for (i = 0; i < mergedSurface->h; i++) {
    1.39 +            for (j = 0; j < mergedSurface->w; j++) {
    1.40 +                
    1.41 +                int index = i * mergedSurface->w + j;
    1.42 +                int mindex = index >> 3;
    1.43 +                int bindex = 7 - (index & 0x7);
    1.44 +                
    1.45 +                if (mask[mindex] & (1 << bindex))
    1.46 +                    pixels[index] |= 0x000000FF;
    1.47 +                else
    1.48 +                    pixels[index] &= 0xFFFFFF00;
    1.49 +            }
    1.50 +        }
    1.51      }
    1.52      
    1.53      imgrep = [ [ NSBitmapImageRep alloc]