Exception in IKImageBrowserView in macOS 10.13 GM

I've got a fairly simply application, with IKImageBrowserView embedded in NSScrollView, as is the most common case. When running on macOS 10.13 High Sierra GM and whenever the IKImageBrowserView is presented and there are enough items in it to make it scrollable, it throws and exception with the following stack trace:


NSInvalidArgumentException
*** -[NSProxy doesNotRecognizeSelector:lastIndex] called!
0x7fff59b71b27  0x7fff7e452c76  0x7fff57c65bfd  0x7fff57b4a510  0x7fff57b49ed8  0x7fff62254b98  0x7fff62288543  0x7fff6226b819  0x7fff59bc66d8  0x7fff7f2cb6c1  0x7fff7f2cb56d  0x7fff7f2cac5d
NSExceptionHandlerExceptionRaiser (in ExceptionHandling) + 160
objc_exception_throw (in libobjc.A.dylib) + 48
+[NSException raise:format:] (in CoreFoundation) + 205
___forwarding___ (in CoreFoundation) + 1456
_CF_forwarding_prep_0 (in CoreFoundation) + 120
IKLimitIndexSetToCount (in ImageKit) + 51
-[IKImageBrowserView(ImageBrowserImport) startScrollPrefetchTask] (in ImageKit) + 157
-[IKTaskManager taskLoop] (in ImageKit) + 2389
__NSThread__start__ (in Foundation) + 1197
_pthread_body (in libsystem_pthread.dylib) + 340
_pthread_body (in libsystem_pthread.dylib) + 0
thread_start (in libsystem_pthread.dylib) + 13


There's really nothing special in the implementation. IKImageBrowserDataSource mrotocol methods looks something like

- (NSUInteger)numberOfItemsInImageBrowser:(IKImageBrowserView *)aBrowser
{
    return [myItems count];
}
- (id)imageBrowser:(IKImageBrowserView *)aBrowser itemAtIndex:(NSUInteger)anIndex
{
    return myItems[anIndex];
}


and items implement IKImageBrowserItem also in a very simple way:


- (NSString *)imageUID
{
    return [self  identifier];
}
- (NSString *)imageRepresentationType
{
    return IKImageBrowserNSImageRepresentationType;
}
- (id)imageRepresentation
{
    return [self image];
}
- (NSString *)imageTitle
{
    return [self displayName];
}
- (BOOL)isSelectable
{
    return YES;
}
- (NSImage *)image
{
    if (!_image)
    {
        NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(128.0, 128.0)];
        [image lockFocus];
        NSRect imageRect = NSMakeRect(.0, .0, 128.0, 128.0);
        [[NSColor redColor] set];
        [NSBezierPath fillRect:imageRect];
        [[NSColor blackColor] set];
        [NSBezierPath strokeRect:imageRect];
        [image unlockFocus];

        [self setImage:image];
    }
    return _image;
}

The UI is implemented using xib file, not a storyboard. Even Apple's official sample code available here suffers from the same issue.

Have anyone find a workaround for this issue. It looks like a bug in the SDK.


Thanks,

-- Dragan

Replies

I get similar errors with the official High Sierra release:


--ImageKit Error: exception in task loop : *** -[NSProxy doesNotRecognizeSelector:lastIndex] called! - task name : scroll-prefetch

I hope that this will be fixed, even if Apple tries to discourage the use of this old control.


Did you make a bug report at https://bugreport.apple.com/web/ ?

Looks like IKImageBrowserView has some issues on 10.13. I see an exception gets thrown just about every second, it appears to get caught but if you run your app with an ObjC exception breakpoint on you'll have to turn it off because you will hit the breakpoint every second:


--ImageKit Error: exception in task loop : *** -[NSArray objectsAtIndexes:]: index set argument is not an NSIndexSet - task name : scroll-prefetch

Call stack looks like this:


_CFThrowFormattedException

-[NSArray objectAtIndexes:]

-[IKImageBrowserView(ImageBrowserImport) startScrollPrefetchTask]

-[IKTaskManager taskLook]

I have filed a bug report 34997377 with the ImageBrowser demo project attached.

This bug seems to be solved in macOS 10.13.1