ScreenSaverDefaults and NSColor

Member
Posts: 67
Joined: 2006.07
Post: #1
I'm writing a screen saver that has some configurable colors, using NSArchiver/NSUnarchiver to store the NSColor objects. Now, most of the time, ScreenSaverDefaults is able to save and load these just fine. But whenever I try to use a color other than the basic ones provided in the default Apple palette ("white", "blue", etc.), it will crash whenever I try to call [color set], and I'll have to manually delete my screen saver's preference file to get it working again.

Are there any pitfalls with ScreenSaverDefaults that I'm unaware of?

(Note: I do convert the colors to NSCalibratedRGBColorSpace so I can access their RGB components, but I've tried removing this and it doesn't seem to help.)

EDIT: I should clarify that by "the basic ones provided in the default Apple palette", I mean the "Apple" palette available in the Color Picker.

Since when was "Fred" a placeholder variable?
Quote this message in a reply
Member
Posts: 67
Joined: 2006.07
Post: #2
Hmm...never mind, it wasn't a problem with ScreenSaverDefaults. I was trying to cache the NSColor objects so I wouldn't have to pull them out of the defaults each frame. Guess that doesn't work.

What I've done instead is cache the RGB values in startAnimation, and then construct the NSColor objects manually using those values when I need them in drawRect. I'm trying to avoid any unnecessary overhead that could be caused by accessing the ScreenSaverDefaults each frame. Although I'm wondering: how significant would the overhead actually be?

Since when was "Fred" a placeholder variable?
Quote this message in a reply
⌘-R in Chief
Posts: 1,265
Joined: 2002.05
Post: #3
I'm going to guess your "caching" problem was that you simply didn't retain the color, it was autoreleased, and the next time you used it, your app died.
Quote this message in a reply
Member
Posts: 67
Joined: 2006.07
Post: #4
*headslap* Of course, the reference count! How could I forget that?

Well, it's working properly now. Thanks for the tip.

(I guess this is what I get for not working with Cocoa in a long time...)

Since when was "Fred" a placeholder variable?
Quote this message in a reply
Post Reply