Domanda

I am testing out using CATiledLayer to draw images and it seems much faster (oddly) than using the default layer even though more drawing operations take place

In drawRect I have:

CGContextRef context = UIGraphicsGetCurrentContext () ;
CGContextSaveGState (context) ;
CGContextTranslateCTM (context, referencePoint.x, referencePoint.y) ;
CGContextScaleCTM(context, zoom * pixelScalingX / SCALE, zoom * pixelScalingY / SCALE) ;
CGContextRotateCTM (context, displayRotation) ;
CGPoint point = CGPointMake(displayCorner.x, displayCorner.y) ;
UIImage *image = [self getChartImage] ;
[image drawAtPoint:point] ;
CGContextRestoreGState(context) ; 

The problem that I am getting is unpredictable access violation crashes at [image drawAtPoint].

This suggests to me a thread safety problem.

This article mentions thread safety

https://developer.apple.com/library/ios/qa/qa1637/_index.html

but appears to say the issues are resolved now. That does not seem to be the case.

My questions then are:

  1. What thread safety issues remain?
  2. If I need to use drawLayerInContext, how do I determine what the drawing rect is? (The except above omits the code to select which images to draw based upon the rect).
  3. If I switch to using Core Graphics for drawing, What additional transform do I need to add to make the image orientation correct?
È stato utile?

Soluzione

The answer is CATiledLayer drawing is not thread safe. You have to use Core Graphics functions only. No UI anything.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top