4

I have an application that applies various filters to an image. It works great on iOS 5 but crashes on 6. Below is a sample of where it's crashing:

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 a value back to m_PixelBuf. Anybody have any idea why this is occuring? What in iOS 6 would cause this?

jscs
  • 63,694
  • 13
  • 151
  • 195
jbender4128
  • 113
  • 1
  • 12
  • Are you using ARC? What is `SAFECOLOR()`? Log the RGB values to make sure your array indexes are correct. – Evan Mulawski Sep 20 '12 at 15:17
  • Can you provide the full error also? –  Sep 20 '12 at 15:31
  • I am not using ARC... SAFECOLOR is #define SAFECOLOR(color) MIN(255,MAX(0,color)). The full error is "Thread 12:EXC_BAD_ACCESS (code=2, address=0x4f50020)" and that is really all I get, nothing showing in the console – jbender4128 Sep 20 '12 at 15:38
  • Loggin r,g,b and red, green, blue vars results in red = 81 | green = 52 | blue = 151 2012-09-20 11:40:54.912 FBPhotoShare[1478:722b] r = 0 | g = 1 | b = 2 – jbender4128 Sep 20 '12 at 15:41

2 Answers2

5

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()), followed by CFDataGetMutableBytePtr() (instead of CFDataGetBytePtr()) if you're going to be manipulating the data's bytes directly.

jscs
  • 63,694
  • 13
  • 151
  • 195
0

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

iosdev1111
  • 1,048
  • 1
  • 13
  • 32