백그라운드 스레드에서 실행중인 완료 블록을 설정하는 프로그램이 있습니다. 블록 안에 CGImageRef를 설정 한 다음 주 스레드에서 내 레이어 내용을 설정합니다. 문제는 메인 스레드 부분에서 응용 프로그램이 충돌하는 경우입니다. fullImage 및 cfFullImage 모두 내 .H스레딩, 블록, CGImageRef 및 스코프와 관련된 문제
requestCompleteBlock completionBlock = ^(id data)
{
// Seems I need to hold onto the data for use later
fullImage = (NSImage*)data;
NSRect fullSizeRect = NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height);
// Calling setContents with an NSImage is expensive because the image has to
// be pushed to the GPU first. So, pre-emptively push it to the GPU by getting
// a CGImage instead.
cgFullImage = [fullImage CGImageForProposedRect:&fullSizeRect context:nil hints:NULL];
// Rendering needs to happen on the main thread or else crashes will occur
[self performSelectorOnMainThread:@selector(displayFullSize) withObject:nil waitUntilDone:NO];
};
내 완료 블록의 마지막 줄은 displayFullSize를 호출하는 것입니다에 선언 아래
이
코드에서, 완료 블록입니다. 그 기능은 다음과 같습니다.- (void)displayFullSize
{
[self setContents:(__bridge id)(cgFullImage)];
}
setContents가 실패하는 이유를 확인했거나 알 수 있습니까?
감사 조
응답 해 주셔서 감사합니다. typedef와 클래스 수준 속성을 추가하는 것이 트릭을 만들었습니다. 'typedef __attribute __ ((NSObject)) CGImageRef RenderedImageRef; @property (강하고 비 구조적) RenderedImageRef renderedImage, ' 해피 코딩 Joe –