EXC_BAD_ACCESS on iOS 6 but not 5 when changing CFDataRef bytes

I have an application that applies various filters to an image. It works fine on iOS 5, but crashes to 6. Below is an example of where it crashes:

CGImageRef inImage = self.CGImage; CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage)); UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef); int length = CFDataGetLength(m_DataRef); for (int i=0; i<length; i+=4) { if(filter == filterCurve){ int r = i; int g = i+1; int b = i+2; int red = m_PixelBuf[r]; int green = m_PixelBuf[g]; int blue = m_PixelBuf[b]; m_PixelBuf[r] = SAFECOLOR(red); // <==== EXC_BAD_ACCESS (code = 2) m_PixelBuf[g] = SAFECOLOR(green); m_PixelBuf[b] = SAFECOLOR(blue); } } 

Notice the bad access point when I try to assign the m_PixelBuf value. Does anyone know why this is happening? What in iOS 6 will cause this?

+4
source share
2 answers

This solves the problem: http://www.iphonedevsdk.com/forum/iphone-sdk-development/108072-exc_bad_access-in-ios-6-but-not-in-ios-5.html

In iOS 6, you need to use CFDataCreateMutableCopy() (instead of CGDataProviderCopyData() ) and then CFDataGetMutableBytePtr() (instead of CFDataGetBytePtr() ) if you are going to manipulate data bytes directly.

+5
source

This is the url where you will find the new class that works with ios 6: https://github.com/kypselia/ios-image-filters/blob/6ef9a937a931f32dd0b7b5e5bbdca6cce2f690dc/Classes/ImageFilter.m

0
source

Source: https://habr.com/ru/post/1435313/


All Articles