# HG changeset patch # User Sam Lantinga # Date 1044131639 0 # Node ID 1970e458070de8a020ac992bb5fcdbee4ba83b8f # Parent 9c9598e4b904ebb2f07fa8407cd1e0d56649c055 Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!) diff -r 9c9598e4b904 -r 1970e458070d src/video/quartz/SDL_QuartzWM.m --- a/src/video/quartz/SDL_QuartzWM.m Sat Feb 01 20:32:44 2003 +0000 +++ b/src/video/quartz/SDL_QuartzWM.m Sat Feb 01 20:33:59 2003 +0000 @@ -227,8 +227,7 @@ NSBitmapImageRep *imgrep; NSImage *img; SDL_Surface *mergedSurface; - Uint8 *surfPtr; - int i,j,masksize; + int i,j; NSAutoreleasePool *pool; SDL_Rect rrect; NSSize imgSize = {icon->w, icon->h}; @@ -244,18 +243,34 @@ goto freePool; } + if (mergedSurface->pitch != + mergedSurface->format->BytesPerPixel * mergedSurface->w) { + SDL_SetError ("merged surface has wrong format"); + SDL_FreeSurface (mergedSurface); + goto freePool; + } + if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) { NSLog(@"Error blitting to mergedSurface"); goto freePool; } if (mask) { - masksize=icon->w*icon->h; - surfPtr = (Uint8 *)mergedSurface->pixels; - #define ALPHASHIFT 3 - for (i=0;i>3]&(1<<(7-j)))?0xFF:0x00; + + Uint32 *pixels = mergedSurface->pixels; + for (i = 0; i < mergedSurface->h; i++) { + for (j = 0; j < mergedSurface->w; j++) { + + int index = i * mergedSurface->w + j; + int mindex = index >> 3; + int bindex = 7 - (index & 0x7); + + if (mask[mindex] & (1 << bindex)) + pixels[index] |= 0x000000FF; + else + pixels[index] &= 0xFFFFFF00; + } + } } imgrep = [ [ NSBitmapImageRep alloc]