iphone - CGContextFillRects: invalid context - Objective C -
i have piece of code give images color need:
- (uiimage*)converttomask: (uiimage *) image { uigraphicsbeginimagecontextwithoptions(image.size, no, image.scale); cgrect imagerect = cgrectmake(0.0f, 0.0f, image.size.width, image.size.height); cgcontextref ctx = uigraphicsgetcurrentcontext(); // draw white background (for white mask) cgcontextsetrgbfillcolor(ctx, 1.0f, 1.0f, 1.0f, 0.9f); cgcontextfillrect(ctx, imagerect); // apply source image's alpha [image drawinrect:imagerect blendmode:kcgblendmodedestinationin alpha:1.0f]; uiimage* outimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return outimage; }
everything works great in first view when add detail view, gives me error (it still works):
cgcontextsetrgbfillcolor: invalid context 0x0. serious error. application, or library uses, using invalid context , thereby contributing overall degradation of system stability , reliability. notice courtesy: please fix problem. become fatal error in upcoming update.
cgcontextfillrects: invalid context 0x0. serious error. application, or library uses, using invalid context , thereby contributing overall degradation of system stability , reliability. notice courtesy: please fix problem. become fatal error in upcoming update.
any idea how rid of error?
thanks.
edit:
the action called nil image. fixed adding condition. @ipmcc comment.
- (uiimage*)converttomask: (uiimage *) image { if (image != nil) { uigraphicsbeginimagecontextwithoptions(image.size, no, image.scale); cgrect imagerect = cgrectmake(0.0f, 0.0f, image.size.width, image.size.height); cgcontextref ctx = uigraphicsgetcurrentcontext(); // draw white background (for white mask) cgcontextsetrgbfillcolor(ctx, 1.0f, 1.0f, 1.0f, 0.9f); cgcontextfillrect(ctx, imagerect); // apply source image's alpha [image drawinrect:imagerect blendmode:kcgblendmodedestinationin alpha:1.0f]; uiimage* outimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return outimage; }else{ return image; } }
try this: in xcode add symbolic breakpoint cgposterror. (add symbolic breakpoint, , symbol field type cgposterror)
when error happen, debugger stop code executions , can check stack of methods calls , check parameters.
Comments
Post a Comment