From 9d12af0330620427eae1d767ee9d6f519ab2275a Mon Sep 17 00:00:00 2001 From: Alex Malko Date: Wed, 1 Jul 2020 09:50:47 -0500 Subject: [PATCH] BUGFIX: EXC_BAD_ACCESS during CGContextDrawImage Why it happened? In my case the image was 500 pixels width but: NSUInteger width = 500 NSUInteger bytesPerPixel = 4 NSUInteger bytesPerRow = 2016 Because the image took 2016 bytes per row instead of 2000 we need to allocate more memory for the "imageData" array. --- .../UIImage Scanline Floodfill/UIImage+FloodFill.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UIImage Scanline Floodfill/UIImage Scanline Floodfill/UIImage+FloodFill.m b/UIImage Scanline Floodfill/UIImage Scanline Floodfill/UIImage+FloodFill.m index f74a47b..3f45a9d 100755 --- a/UIImage Scanline Floodfill/UIImage Scanline Floodfill/UIImage+FloodFill.m +++ b/UIImage Scanline Floodfill/UIImage Scanline Floodfill/UIImage+FloodFill.m @@ -49,7 +49,7 @@ - (UIImage *) floodFillFromPoint:(CGPoint)startPoint withColor:(UIColor *)newCol NSUInteger bytesPerRow = CGImageGetBytesPerRow(imageRef); NSUInteger bitsPerComponent = CGImageGetBitsPerComponent(imageRef); - unsigned char *imageData = malloc(height * width * bytesPerPixel); + unsigned char *imageData = malloc(height * bytesPerRow); CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);