IKImageView hangs?

I'm writing a scanning application that is getting images from a document scanner, turning them into NSImages and then displaying them in an IKImageView. About half of the time, however, when I try to call setImage:ImageProperties in IKImageView, it just hangs.

It only happens when I'm getting the image directly from the scanner, as I'm scanning. if I've gotten pages from the scanner, but not displayed them, but then after I step scanning, page up and down through pages, it works fine and never hangs (as far as I've seen).

The NSImage that gets scanned gets turned into a PDFPage and then inserted into a PDFDocument. Then, when I want to display a page, I get the image from the Page and display it. (Yes, I take an NSImage, turn it into a PDF, and then turn it back into an NSImage...)

Here is some code:

This is in my IKImageView subclass ( that also replaces isFlipped, and sets animates to NO)

-(void) setNSImage:(NSImage*) nsImage
{
CGImageRef cgImage = nsImageToCGImage(nsImage);
[self setImage:cgImage imageProperties:NULL];
}
CGImageRef nsImageToCGImage(NSImage* image)
{
NSData * imgData = [image TIFFRepresentation];
CGImageRef imgRef = 0;
if(imgData)
{
CGImageSourceRef imageSource =
CGImageSourceCreateWithData((CFDataRef)imgData, NULL);
imgRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
}
return imgRef;
}

To get the NSImage from the PDFDocument:

-(NSImage*) currentImage
{
return [[NSImage alloc] initWithData: [[doc pageAtIndex: pageNum] dataRepresentation]];
}

Here's the call stack where I hang:

#0 0x94a3a066 in _semwaitsignal
#1 0x94a39d22 in pthread_condwait
#2 0x94a3b9b8 in pthreadcondwait$UNIX2003
#3 0x95238477 in -[NSViewHierarchyLock _lockForWriting:handler:]
#4 0x9523824d in -[NSViewHierarchyLock lockForWritingWithExceptionHandler:]
#5 0x9527d871 in -[NSView setBoundsOrigin:]
#6 0x9527d68c in -[NSClipView setBoundsOrigin:]
#7 0x93721e03 in -[IKImageLayer autoResizeToRect:allowZoomIn:]
#8 0x9371f228 in -[IKImageLayer _updateLayer:]
#9 0x93723098 in -[IKImageLayer doSetImage:imageProperties:imageState:options:]
#10 0x9371f5c1 in -[IKImageLayer setImage:imageProperties:imageState:options:]
#11 0x93731d35 in -[IKComposer setImage:imageProperties:imageState:options:]
#12 0x9372ace1 in -[IKImageView(IKPrivate) setImage:imageProperties:imageState:options:]
#13 0x9372c421 in -[IKImageView setImage:imageProperties:]
#14 0x00005bb4 in -[FlippedIKImageView setNSImage:] at FlippedIKImageView.m:84

Mac Mini, Mac OS X (10.6.3)

Posted on Jul 29, 2010 3:14 PM

Reply
2 replies

Jul 29, 2010 5:58 PM in response to xnav

yes I am. and in fact I AM calling the update code from a spawned NSThread...

hrm. So, I need to capture the runloop before I go into the thread, pass that around so that when I am ready to display, I can tell the main runloop to do the display? wow that's ugly.

Well, it DOES seem to work...

now, if only I could come up with a way of speeding up IKImageView's refresh... ew.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

IKImageView hangs?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.