2010-05-11 5 views
0

"때때로"아래의 코드는 장치에서 실행할 때 충돌 (EXC_BAD_ACCESS)을 발생시킵니다. 시뮬레이터에 절대로 없어.drawRect의 EXC_BAD_ACCESS

모달 뷰 컨트롤러를 테이블보기 컨트롤러 위에 오버레이하여 재현합니다. 일반적으로 모달 뷰 컨트롤러가 닫힐 때 발생합니다.

왜 그런가?

CGContextRef context = UIGraphicsGetCurrentContext(); 

//set the background of the cell 
[self.backgroundColor set]; 
CGContextFillRect(context, rect); 

// get cached image 
UIImage *image = [[ImageUtil sharedInstance] getImageByRouteType:route.type]; 
CGSize imageSize = CGSizeMake(IMAGE_WIDTH, IMAGE_WIDTH); 
// DEBUGGER STOPS ON THIS NEXT LINE, image object is fine though 
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)]; 

[...] 

감사

+0

UIImages CGImage 속성을 공개하지 못할 수 있습니다. 어디서나 CGImage 속성에 액세스하고 있습니까? – tonklon

+0

답변을 주셔서 감사 합니다만, 아니요, 어디서나 CGImage 속성에 액세스하지 않고 있습니다 ... – nicktmro

답변

1

당신이 NSOperationQueue 같은 여러 트레드 상황에서 drawInRect를 사용하는 경우, 하나 개 이상의 스레드에서 호출된다 "drawInRect"을 방지하기 위해 잠금을 사용하려고합니다. 나는 비슷한 문제를 만났고 이런 식으로 해결했다.

@synchronized([UIImage class]){ 
    UIGraphicsBeginImageContext(newSize); 
    CGRect rect = CGRectMake(0.0, 0.0, newSize.width, newSize.height); 
    [self drawInRect: rect]; 
    newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

}