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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex