简体   繁体   English

更改CFDataRef的字节时,iOS 6上为EXC_BAD_ACCESS,而不是5上

[英]EXC_BAD_ACCESS on iOS 6 but not 5 when changing bytes of a CFDataRef

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: 它在iOS 5上运行良好,但在6上崩溃。下面是崩溃的示例:

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 . 当我尝试将值分配回m_PixelBuf时,请注意错误的访问点。 Anybody have any idea why this is occuring? 有人知道为什么会这样吗? What in iOS 6 would cause this? 在iOS 6中会导致什么?

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 这样可以解决问题: 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. 在iOS 6中,如果要直接操作数据的字节,则需要使用CFDataCreateMutableCopy() (而不是CGDataProviderCopyData() ),然后是CFDataGetMutableBytePtr() (而不是CFDataGetBytePtr() )。

这是您在其中找到适用于ios 6的新类的URL:https://github.com/kypselia/ios-image-filters/blob/6ef9a937a931f32dd0b7b5e5bbdca6cce2f690dc/Classes/ImageFilter.m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM