drawRect: / renderInContext: problemas

Parece tener un pequeño problema al tratar de ubicar mi visión en un contexto.

Mi configuración básica es, tengo un controlador de vista que posee unUIPageViewController en el que carga controladores con vistas que pueden dibujarse con el dedo de los usuarios. Básicamente tengo un libro en el que se puede dibujar.

Cuando la página está girada en el libro, guardo la imagen llamando

<code>- (UIImage *)wholeImage {
    // Render the layer into an image and return
    UIGraphicsBeginImageContext(self.bounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *wholePageImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return wholePageImage;
}
</code>

El valor de retorno de esto se guarda en un archivo. Sin embargo, cuando llamo a este método de guardar la línea

<code>[self.layer renderInContext:UIGraphicsGetCurrentContext()];
</code>

recibe un golpe, que parece hacer una llamada a midrawRect: método, que se reemplaza de la siguiente manera,

<code>- (void)drawRect:(CGRect)rect {
    // Draw the current state of the image
    [self.currentImage drawAtPoint:CGPointMake(0.0f, 0.0f)];
    CGPoint midPoint1 = [self midPointOfPoint1:previousPoint1 point2:previousPoint2];
    CGPoint midPoint2 = [self midPointOfPoint1:currentPoint point2:previousPoint1];

    // Get the context
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    // Add the new bit of line to the image
    [self.layer renderInContext:context];
    CGContextMoveToPoint(context, midPoint1.x, midPoint1.y);
    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, midPoint2.x, midPoint2.y); 
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, self.lineWidth);
    if (self.drawMode == LNDrawViewDrawModeTipex) CGContextSetBlendMode(context, kCGBlendModeClear);
    else CGContextSetBlendMode(context, kCGBlendModeCopy);
    CGContextSetStrokeColorWithColor(context, self.lineColour.CGColor);
    CGContextStrokePath(context);

    // Call super
    [super drawRect:rect];
}
</code>

lo que tiene sentido, pero parece que se llama de forma recursiva hasta que finalmente obtengo un EXC_BAD_ACCESS en esta línea

<code>[self.currentImage drawAtPoint:CGPointMake(0.0f, 0.0f)];
</code>

Estoy completamente perdido en cuanto a lo que está causando esto y me ha estado volviendo loco.

Si ayuda, mi pila de llamadas comienza así.

y luego continúa de forma recursiva hasta que finalmente termina con

¡Realmente apreciaría y ayudaría y comprendería lo que cualquiera puede dar!

EDITAR: (toques movidos añadidos)

<code>-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    // Get the touch
    UITouch *touch = [touches anyObject];

    // Get the points
    previousPoint2 = previousPoint1;
    previousPoint1 = [touch previousLocationInView:self];
    currentPoint = [touch locationInView:self];

    // Calculate mid point
    CGPoint mid1 = [self midPointOfPoint1:previousPoint1 point2:previousPoint2]; 
    CGPoint mid2 = [self midPointOfPoint1:currentPoint point2:previousPoint1];

    // Create a path for the last few points
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, mid1.x, mid1.y);
    CGPathAddQuadCurveToPoint(path, NULL, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
    CGRect pathBounds = CGPathGetBoundingBox(path);
    CGPathRelease(path);

    // Take account of line width
    pathBounds.origin.x -= self.lineWidth * 2.0f;
    pathBounds.origin.y -= self.lineWidth * 2.0f;
    pathBounds.size.width += self.lineWidth * 4.0f;
    pathBounds.size.height += self.lineWidth * 4.0f;

    UIGraphicsBeginImageContext(pathBounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    self.currentImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [self setNeedsDisplayInRect:pathBounds];    
</code>

}

Respuestas a la pregunta(1)

Su respuesta a la pregunta