CocoaDev

Edit AllPages

_NSStateMarker is something that I didn’t even know existed until recently, and I still don’t know what it does, but it’s causing a weird bug in my app. From Google searches, I’ve found that the class points out selection information for NSArrayControllers. I modified the GraphicBindings example by mmalc to work as a Keynote-like slide editor, and I’ve bound objects and colors to each slide. For example, I just copied the existing methods for binding my NSColor value to the NSView subclass:

So here’s what happens: everything is fine and dandy until the user goes and clicks on the desktop or another window (taking away the focus from the document and view), and then tries to refocus on the application (thus calling my view’s displayRect: method). At that point, my drawing code calls self color] set], but that no longer returns the [[NSColor, but instead returns a copy of NSStateMarker. That brings my app’s drawing to a grinding halt until I figured out that I must change the selection in the NSArrayController (by clicking on the table view). After doing that, it is able to draw again… until I click outside of that document window again. Why would the NSArrayController lose the selected object when I click outside of the window? or, is there some way that I can get useful information out of that NSStateMarker for me to figure out what’s going on?


I don’t see any of your drawing code here, nor the implementation of [self color], wouldn’t it be better to actually include the code that’s going wrong?


Okay, here it is, and very long… don’t say I didn’t warn you ;)


I still don’t see the implementation for [self color]. Is it this non-obvious what the important code is, even when it’s pointed out?


Well, that probably doesn’t do much, but okay:

… wouldn’t it raise an error at this point if the data it recieves isn’t the same as what it expects (seeing as how I told it to expect NSColor)?


You know that it doesn’t do much. I didn’t know this until you posted it, and even though it doesn’t do much I had no idea what not-much it actually did until you showed the code. You’re having trouble solving this problem with the entire app in front of you; imagine how difficult it is for everybody else, seeing only bits of the code. Showing every relevant piece is essential.

The NSColor * is purely a compile time construct that is used by the compiler to do some very basic static checking on your code. There are no runtime consequences to assigning an object of one type to a variable of another.

As far as your problem, it’s either memory management or somebody is changing the value for that key path. Use NSZombieEnabled to search for the former, and see if you can poke around in the debugger and use logging to search for the latter.