iosobjective-ccgcontextref

iOS - Invalid context on CGContextRotateCTM


When I try to run my rotate method I get the following error:

<Error>: 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.

Rotate method:

UIImage* rotate(UIImage* src, double degrees) {
    UIGraphicsBeginImageContext(src.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextRotateCTM (context, radians(degrees));
    [src drawAtPoint:CGPointMake(0, 0)];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Do you have any idea what I'm doing wrong?


Solution

  • either the image is nil

    OR

    it is of zero size. => empty image