2013-10-15 19 views
22

Pracuję nad aplikacją iOS, która używa kamery na żywo do skanowania kodów kreskowych i kodów QR. Czasami jednak pojawiają się błędy. Błędy te nie powodują awarii aplikacji, ale dobrze jest je naprawić. Są to błędy:CGContextSaveGState invalid context

<Error>: CGContextSaveGState: 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. 
<Error>: CGContextSetBlendMode: 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. 
<Error>: CGContextSetAlpha: 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. 
<Error>: CGContextTranslateCTM: 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. 
<Error>: CGContextScaleCTM: 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. 
<Error>: 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. 
<Error>: CGContextRestoreGState: 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. 
<Error>: CGContextSetInterpolationQuality: 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. 
<Error>: CGContextSetAllowsAntialiasing: 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. 
<Error>: CGContextTranslateCTM: 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. 
<Error>: CGContextScaleCTM: 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. 
<Error>: CGContextFlush: 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. 
<Error>: 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. 
<Error>: CGContextSetInterpolationQuality: 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. 
<Error>: CGContextSetAllowsAntialiasing: 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. 
<Error>: CGContextTranslateCTM: 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. 
<Error>: CGContextScaleCTM: 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. 
<Error>: CGContextFlush: 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. 
<Error>: 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. 

I wierzę, kod ten jest odpowiedzialny za wiadomości błędów:

- (UIImage *)cropImage:(UIImage *)oldImage sideCrop:(float)crop { 
CGSize imageSize = oldImage.size; 
UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageSize.width - 2*crop, 
                imageSize.height), 
             NO, 
             0.); 
[oldImage drawAtPoint:CGPointMake(-crop, 0) 
      blendMode:kCGBlendModeCopy 
       alpha:1.]; 
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return croppedImage; 
} 

Odpowiedz

57

Sposób UIGraphicsBeginImageContextWithOptions jest przekazywana z jednej width = 0 rozmiaru i/lub height = 0. Debuguj i rozwiąż problem.

+0

Niestety, to rozwiązanie może rozwiązać niektóre wystąpienia tego problemu, ale wszystkie. – Biclops

+3

Omg, dziękuję. Co za okropnie bezużyteczny komunikat o błędzie dla tak prostego problemu. – devios1

+0

To działało również na placu zabaw. Właśnie upuściłem '' 'UIGraphicsBeginImageContextWithOptions (CGSize (szerokość: 500, wysokość: 500), false, 1.0)' '' przed linią, która wysadzała w powietrze. :) –

1

otrzymuję ten błąd, gdy robi jak

UIGraphicsBeginImageContextWithOptions(gradientLayer.bounds.size, 
              NO, 
              1.0f); 
    [gradientLayer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage *gradientColorImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

gdzie

(lldb) po gradientLayer.bounds 
(origin = (x = 0, y = 0), size = (width = 0, height = 0)) 
(origin = (x = 0, y = 0), size = (width = 0, height = 0)) 
(lldb) po gradientLayer.bounds.size 
(width = 0, height = 0) 
(width = 0, height = 0) 

więc gdy szerokość lub wysokość granicach wynosi zero.

tak właśnie zrobiłem prosty szerokość non sprawdzanie zera w kodzie jak

+ (UIImage *)gradientColorImageWithColors:(NSArray *)colorsArray gradientType:(GradientImageType)type andSize:(CGSize)imageSize addingLightEffect:(BOOL)addLightEffect { 

if(imageSize.width==0) { 
    return nil; 
} 

używałem tej metody zmieniających wygląd UINavigationBar:

[[UINavigationBar appearanceWhenContainedIn: [UINavigationController class], nil] setBackgroundImage: [UIImage gradientColorImageWithColors:@[(id)COLORS_NAVIGATION_BAR_1.CGColor, (id)COLORS_NAVIGATION_BAR_2.CGColor] 
                                  gradientType:GradientImageTypeHorizontal 
                                   andSize:(CGSize){CGRectGetWidth([UIScreen mainScreen].bounds), 1.0f}] 
                        forBarMetrics:UIBarMetricsDefault]; 
+1

TAK! Po przejrzeniu wszystkich innych wątków i próbowaniu rozwiązań, to jest to, które ma sens. Nieprawidłowy kontekst pojawił się naprawdę, dopóki nie zmieniłem symbolu zastępczego '[UIImage new]' dla istniejącego obrazu z '[UIImage imageNamed: @" placeholder "]', który jest rysowany w kontekście. – igraczech

1

w przypadku ktokolwiek inny pracuje do tego problemu, w moim przypadku nieprawidłowo wywoływać path.stroke() i path.fill() bezpośrednio na ścieżce CAShapeLayer. Te metody powinny być wywoływane tylko wtedy, gdy faktycznie masz kontekst (tj. Wewnątrz draw(rect:)).

Powiązane problemy