iOS : CGContextStrokePath(context) crashes with EXC_BAD_ACCESS in iOS 12

197 views Asked by At

I am trying to draw a signature using CALayer with CGContextStrokePath(context) but it's crashing with tricky crash with below error in iOS 12 only:

malloc: Incorrect checksum for freed object 0x1196538c8: probably modified after being freed. Corrupt value: 0x4069e00000000000 (899,0x17190b000) malloc: *** set a breakpoint in malloc_error_break to debug

Code Snippet:

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)contx {
    if (layer == canvasLayer) {
        //we don't want this to fire after the background layer update
        //and after the path has been released
        if (!touching) return;
        CGContextAddPath(contx, path);
        CGContextSetLineWidth(contx, 7.0f);
        CGContextStrokePath(contx);
    }
    else if (layer == bckLayer) {
        CGContextSaveGState(contx);
        CGContextTranslateCTM(contx, 0, backgroundLayer.bounds.size.height);
        CGContextScaleCTM(contx, 1.0, -1.0);
        CGImageRef ref = cacheImage.CGImage;
        CGContextDrawImage(contx, backgroundLayer.bounds, ref);
        CGContextRestoreGState(ctx);
    }
}
0

There are 0 answers