Skip to main content

Intermittent EXC_BAD_ACCESS exception with CATitledLayer



I am having some problems with an app that keeps crashing intermittently. Code below is in a UIView with CATiledLayer as its backing layer:







- (UIBezierPath *)path

{

if(_path == nil){



_path = [UIBezierPath bezierPath];

CGFloat lineWidth = 5;

[_path setLineWidth:lineWidth];

[_path setLineJoinStyle:kCGLineJoinRound];

[_path setLineCapStyle:kCGLineCapRound];



[_path moveToPoint:CGPointMake(100, 100)];

[_path addLineToPoint:CGPointMake(200,200)];

[_path addLineToPoint:CGPointMake(150,200)];

[_path addLineToPoint:CGPointMake(50,400)];

_path closePath];



return _path;

}

return _path;

}



- (void)drawRect:(CGRect)rect

{

[[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context

[self.path stroke];

}







I get the following error code:







Single stepping until exit from function _ZN2CG4Path15apply_transformERK17CGAffineTransform, which has no line number information.







There doesn't seem to be any pattern to when the error occurs. It can seems to occur at some point doing scrolling or zooming. Sometimes in crashes as soon as I zoom/scroll. Sometimes I can zoom and scroll for a while until it crashes.





I know before iOS4 the UIKit was not thread safe and could not be used with CATiledLayers. See tech note My problem (i think) seems to be a thread issue. Surely UIKit can't be to blame?


Comments

  1. Try to make the path property atomic.

    Also, you should probably modify drawRect to the following:

    - (void)drawRect:(CGRect)rect
    {
    [[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:0.45] setStroke];//sets stroke color in current context
    @synchronized(self) {
    [self.path stroke];
    }


    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.