ios - CGContext invalid context 0x0 -
i drawing cglayers, creating layer , drawing layer graphics context in drawrect method, way
- (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); if(self.currentdrawinglayer == nil) { cglayerref layer = cglayercreatewithcontext(context, bounds.size, null); self.currentdrawinglayer = layer; } cgcontextdrawlayerinrect(context, self.bounds, self.currentdrawinglayer); }
i drawing operations in touchesmoved function
-(void)touchesmoved:(nsset *)touches withevent:(uievent *)event { cgcontextref layercontext = cglayergetcontext(self.currentdrawinglayer); cgcontextsetlinecap(layercontext, kcglinecapround); cgcontextsetlinejoin(layercontext, kcglinejoinround); cgcontextsetallowsantialiasing(layercontext, yes); cgcontextsetshouldantialias(layercontext, yes); cgcontextsetblendmode(layercontext,kcgblendmodeclear); cgcontextsetlinewidth(layercontext, self.erasewidth); cgcontextbeginpath(layercontext); cgcontextaddpath(layercontext, mutablepath); cgcontextstrokepath(layercontext); cgpathrelease(mutablepath); [self setneedsdisplay]; }
but when start drawing, error messages cgcontext functions used in touches moved, of listing few below.
<error>: cgcontextbeginpath: 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. <error>: cgcontextaddpath: 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.
- i know error because, layer not created yet, , because of that, error, layer should created in drawrect method because, graphics context alive.
- if call
[self setneedsdisplay]
first , drawing functions, , again @ last[self setneedsdisplay]
, works fine, no errors, dont think, or rather dont know wheteher right thing do.
in -touchesmoved:withevent:
method, return if don’t have layer yet. user can’t draw if can’t see view, after all. i.e. add
if (!self.currentdrawinglayer) return;
at top.
Comments
Post a Comment