- [UIImage CGImage] returns zero

I am wondering under what circumstances this code breaks into second . In other words, when does it -[UIImage CGImage]return nil? The documentation here is not very important.

- (void)setImage:(UIImage *)anImage {
    assert(anImage);
    CGImageRef cgimage = anImage.CGImage;
    assert(cgimage);
}

I'm sure UIImage is correct, as it came from a suite of applications. So far, I have not been able to reproduce this case, but I see some reports of user crashes.

+3
source share
4 answers

Another possibility is that you are using multiple threads at the same time, accessing the same UIImage object; this happened in my code with the same symptom.

, , .

+2

, :

UIImage CIImage, NULL.

+5

As far as I know, if the first statement passes (showing that anImage is not equal to zero), it means that it cannot load the image. Make sure the image is copied to your kit.

+1
source

The case where there anImagewould be non-zero, but cgimagewould be nil can be invented as follows:

UIImage* myImage = [[UIImage alloc] initWithCGImage:nil];

As the previous answers showed, there are other ways to find yourself in such a scenario.

+1
source

Source: https://habr.com/ru/post/1794443/


All Articles