Feb
20

The Case of the Mysterious “Can’t cache image” Error

I’ve been working a bit on Desktopple Pro. It doesn’t matter how thorough or how long the test, Beta Tests can’t catch everything. So whenever there’s a release, you’re always going to have a lingering bug or two. And today, I’ve been squashing those bugs.

I had just done a build, tried to load the Desktopple Pro preference pane to test it, and, for some strange reason, it wouldn’t load. A quick check of the Console log revealed this rather terse error message:

Can't cache image

I tried a fresh build, and I got the same error. Puzzled, I then turned to Google. A search revealed a lot of hits for that phrase, but no real answers on the cause or the solution.

Worse, the bugs I had been working on were in the Desktopple app, not the preference pane, so the problem wasn’t a result of a code change, but something that was already there!

Fortunately, after a few hours of pulling out my hair, I finally figured it out. And since Google didn’t help, and there really weren’t any solutions out there, I’m posting mine. Hopefully, it will save others the frustration of trying to figure out this unhelpful error message.

Turns out that if you -lockFocus on an NSImage with either a zero width or a zero height, you’ll get the “Can’t cache image” error (other issues may cause it as well).

The solution is easy: before locking focus on the image, make sure the image has non-zero height and width.

Look for this fix (as well as a couple others in Desktopple Pro) in a day or so.

One Response to “The Case of the Mysterious “Can’t cache image” Error”

  1. Andre Pang Says:

    Oooo, just wanted to say a big thank you — I owe you a beer if you ever make it to WWDC. I reckon you saved me a good couple of hours just then :-) .

Leave a Reply