0

백그라운드 스레드에서 실행중인 완료 블록을 설정하는 프로그램이 있습니다. 블록 안에 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가 실패하는 이유를 확인했거나 알 수 있습니까?

감사 조

답변

3

cgFullImage이 유지되지 않습니다. CGImage Core Foundation 객체는 할당이 해제되어 있고 할당 해제 된 객체를 사용하고 있습니다.

CGImageRef과 같은 핵심 기반 개체 포인터 유형은 ARC에서 관리하지 않습니다. 인스턴스 변수에 __attribute__((NSObject))이라는 주석을 달거나 인스턴스 변수의 유형을 id과 같은 Objective-C 객체 포인터 유형으로 변경해야합니다.

+0

응답 해 주셔서 감사합니다. typedef와 클래스 수준 속성을 추가하는 것이 트릭을 만들었습니다. 'typedef __attribute __ ((NSObject)) CGImageRef RenderedImageRef; @property (강하고 비 구조적) RenderedImageRef renderedImage, ' 해피 코딩 Joe –