Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<Error>: CGBitmapContextCreateImage: invalid context 0x0

I have an app which combines two images using the CGContextDrawImage function. Here's my problem. Only one image is appearing while the other does not appear in the ios simulator for the iphone 5 while on the iphone simulator for iphone 3 there's no problem in displaying those images and I don't have any problem. By the way here are the lists of the errors that Xcode is giving me.

//ERRORS

: CGContextRotateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

: CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

: CGBitmapContextCreateImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Can anyone help me please? Thanks in advance.

Here's my sample code:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGRect xFirstFrame = m_pUserImgView.frame;
int nWidth = xFirstFrame.size.width;
int nHeight = xFirstFrame.size.height;
CGFloat rScaleX;
CGPoint xOrgCenter;
UIImage* pJustinImage = m_pJustinImgView.image;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    xOrgCenter = CGPointMake(384, 512);
}
else
    if ([self appDelegate].isiPhone5 == YES)
    {
        xOrgCenter = CGPointMake(160, 284);
    }
    else
    {
        xOrgCenter = CGPointMake(160, 240);
    }
CGContextRef buf_context = CGBitmapContextCreate(nil, nWidth, nHeight, 8, nWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGRect rect = CGRectMake(0,0, nWidth, nHeight);
CGRect xSecRect = m_pJustinImgView.bounds;
UIGraphicsPushContext(buf_context);
CGContextClearRect(buf_context, rect);
CGContextDrawImage(buf_context, rect, m_pUserImgView.image.CGImage);
//Transform Context
CGAffineTransform pTransform = m_pJustinImgView.transform;
CGAffineTransform xRealTrans = CGAffineTransformMake(pTransform.a, pTransform.b, pTransform.c, pTransform.d, pTransform.tx, -pTransform.ty);

CGPoint xOrgPoint = CGPointMake(xOrgCenter.x + pTransform.tx, xOrgCenter.y - pTransform.ty);
CGFloat rDegree = [self CalcRotateAngle:xRealTrans];
CGContextTranslateCTM(buf_context, xOrgPoint.x, xOrgPoint.y);
CGContextRotateCTM(buf_context, -rDegree);
rScaleX = sqrtf(pTransform.a * pTransform.a + pTransform.c * pTransform.c);
CGContextDrawImage(buf_context, CGRectMake(- xSecRect.size.width * rScaleX/2, - xSecRect.size.height * rScaleX/2, xSecRect.size.width * rScaleX , xSecRect.size.height * rScaleX), pJustinImage.CGImage);
UIGraphicsPopContext();

CGImageRef image = CGBitmapContextCreateImage(buf_context);
CGContextRelease(buf_context);

UIImage* pCombImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);

return pCombImage;

}

//Code for loading the images

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGRect xFirstFrame = m_pBackImageView.frame;



int nWidth = xFirstFrame.size.width;
int nHeight = xFirstFrame.size.height;
CGFloat rScaleX;
CGPoint xOrgCenter;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    xOrgCenter = CGPointMake(384, 512);
}
else
{
    if ([self appDelegate].isiPhone5 == YES)
    {
        xOrgCenter = CGPointMake(160, 284);
    }
    else
    {
        xOrgCenter = CGPointMake(160, 240);
    }
}

CGContextRef buf_context = CGBitmapContextCreate(nil, nWidth, nHeight, 8, nWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGRect rect = CGRectMake(0,0, nWidth, nHeight);
CGRect xSecRect = m_pUserImgView.bounds;
UIGraphicsPushContext(buf_context);
CGContextClearRect(buf_context, rect);
CGContextDrawImage(buf_context, rect, m_pBackImageView.image.CGImage);
//Transform Context
CGAffineTransform pTransform = m_pUserImgView.transform;
CGAffineTransform xRealTrans = CGAffineTransformMake(pTransform.a, pTransform.b, pTransform.c, pTransform.d, pTransform.tx, -pTransform.ty);

CGPoint xOrgPoint = CGPointMake(xOrgCenter.x + pTransform.tx, xOrgCenter.y - pTransform.ty);
CGFloat rDegree = [self CalcRotateAngle:xRealTrans];
CGContextTranslateCTM(buf_context, xOrgPoint.x, xOrgPoint.y);
CGContextRotateCTM(buf_context, -rDegree);
rScaleX = sqrtf(pTransform.a * pTransform.a + pTransform.c * pTransform.c);
CGContextDrawImage(buf_context, CGRectMake(- xSecRect.size.width * rScaleX/2, - xSecRect.size.height * rScaleX/2, xSecRect.size.width * rScaleX , xSecRect.size.height * rScaleX), m_pUserImgView.m_pViewImage.CGImage);
UIGraphicsPopContext();

CGImageRef image = CGBitmapContextCreateImage(buf_context);
CGContextRelease(buf_context);

UIImage* pCombImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);

return pCombImage;
like image 810
SwiftlyNily Avatar asked Dec 25 '22 18:12

SwiftlyNily


1 Answers

Try this: In xcode add symbolic breakpoint to CGPostError. (Add symbolic breakpoint, and to Symbol field type CGPostError)

When error happen, debugger will stop code executions and you can check stack of methods calls and check parameters. Look for 0 sized surfaces. Some param will have size of 0.

like image 174
Juraj Antas Avatar answered Dec 28 '22 06:12

Juraj Antas