如何在Objective-C CGIMageRef中对齐内存以修复EXC_ARC_DA_align错误

如何在Objective-C CGIMageRef中对齐内存以修复EXC_ARC_DA_align错误,objective-c,c,core-graphics,memory-alignment,cgimageref,Objective C,C,Core Graphics,Memory Alignment,Cgimageref,多年来,我一直在我的应用程序中使用这段代码。它从我传入的CGImageRef和黑白蒙版中剪切出一组片段 我正在尝试将代码迁移到一个布局将基于自动布局和约束的环境中 在我尝试在iPad3、iPhone5或4s上运行autolayout之前,它一直与autolayout完美配合 经过大量的研究,我相信它是崩溃的原因是内存对齐问题与此错误 EXC_错误访问(代码=EXC_ARM_DALIGN,地址=0x5baa20) 我相信我需要以某种方式调整每个组件的位/字节数,以确保结果始终在内存中对齐,以避免激

多年来,我一直在我的应用程序中使用这段代码。它从我传入的CGImageRef和黑白蒙版中剪切出一组片段

我正在尝试将代码迁移到一个布局将基于自动布局和约束的环境中

在我尝试在iPad3、iPhone5或4s上运行autolayout之前,它一直与autolayout完美配合

经过大量的研究,我相信它是崩溃的原因是内存对齐问题与此错误

EXC_错误访问(代码=EXC_ARM_DALIGN,地址=0x5baa20)

我相信我需要以某种方式调整每个组件的位/字节数,以确保结果始终在内存中对齐,以避免激怒统治问题设备的ARMV7神

我在网上找到了一些例子,但我还没有成功地将它们应用于这种情况

我有另一条路径,在那里我可以硬编码我的尺寸,这不会导致崩溃,但我不得不放弃数天的自动布局工作来硬编码

请帮忙

    - (UIImage*) maskImage2:(CGImageRef)image withMask:(UIImage *)maskImage withFrame:(CGRect)currentFrame {
@autoreleasepool {

    CGFloat scale = [self adjustScale];


    CGRect scaledRect = CGRectMake(currentFrame.origin.x*scale, currentFrame.origin.y*scale, maskImage.size.width*scale, maskImage.size.height*scale);
    //Rect scaled up to account for iPad 3 sizing

    NSLog( @"%@ origin", NSStringFromCGRect(scaledRect));
    CGImageRef tempImage = CGImageCreateWithImageInRect(image, scaledRect);// Cut out the image at the size of the pieces
    CGImageRef maskRef = maskImage.CGImage;  //Creates the mask to cut out the fine edge and add backing layer

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false);
    CGImageRef colorsHighlights = CGImageCreateWithMask(tempImage, mask);//Colors with tran transparent surround

    CFRelease(tempImage);

    CGSize tempsize = CGSizeMake(maskImage.size.width, maskImage.size.height);

    CFRelease(mask);
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(tempsize.width+5, tempsize.height+5), NO, scale);
    CGContextRef context = UIGraphicsGetCurrentContext();

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        CGContextSetShadow(context, CGSizeMake(1, 2), 2);
    }else{
        CGContextSetShadow(context, CGSizeMake(.5, .5), 1);
    }
    [[UIImage imageWithCGImage:colorsHighlights scale:scale orientation:UIImageOrientationUp] drawInRect:CGRectMake(0, 0, tempsize.width, tempsize.height)]; // <<<< Crash is here
    CFRelease(colorsHighlights);

    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return finalImage;
}
-(UIImage*)掩码2:(CGImageRef)带掩码的图像:(UIImage*)带帧的掩码:(CGRect)当前帧{
@自动释放池{
CGFloat刻度=[自调整刻度];
CGRect scaledRect=CGRectMake(currentFrame.origin.x*比例,currentFrame.origin.y*比例,maskImage.size.width*比例,maskImage.size.height*比例);
//Rect按比例放大,以适应iPad3的尺寸
NSLog(@“%@原点”,NSStringFromCGRect(scaledRect));
CGImageRef tempImage=CGImageCreateWithImageInRect(image,scaledRect);//按片段大小剪切图像
CGImageRef maskRef=maskImage.CGImage;//创建遮罩以剪切精细边缘并添加背衬层
CGImageRef掩码=CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(马斯克里夫),
CGImageGetDataProvider(maskRef),NULL,false;
CGImageRef colorsHighlights=CGImageCreateWithMask(tempImage,mask);//带有透明环绕的颜色
CFRelease(tempImage);
CGSize tempsize=CGSizeMake(maskImage.size.width,maskImage.size.height);
释放(面罩);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(tempsize.width+5,tempsize.height+5),NO,scale);
CGContextRef context=UIGraphicsGetCurrentContext();
if(UI\u USER\u INTERFACE\u IDIOM()==UIUserInterfaceIdiomPad){
CGContextSetShadow(上下文,CGSizeMake(1,2,2));
}否则{
CGContextSetShadow(上下文,CGSizeMake(.5,5),1);
}

[[UIImage imageWithCGImage:colorsHighlights scale:scale-orientation:UIImageOrientationUp]drawInRect:CGRectMake(0,0,tempsize.width,tempsize.height)];//崩溃发生在哪一行?它在[[UIImage imageWithCGImage:colorsHighlights scale:scale-orientation:UIImageOrientationUp]DrawinRectRectMake上消亡(0,0,tempsize.width,tempsize.height)];