Error when clicking into a programmatically-defined NSPopUpButton

Hello,

This error happens only certain times (after creating a new document). If I save and re-open, it fails. If I save, open another document, then open the first one, it works. Any idea? Have someone had the same error?

Thanks for deciphering this:

2013-03-23 11:36:52.977 Demiurge[97164:303] *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
2013-03-23 11:36:52.979 Demiurge[97164:303] (
0 CoreFoundation 0x00007fff89814b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff833c53f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff897d91d7 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 119
3 CoreFoundation 0x00007fff897e76bb +[NSDictionary dictionaryWithObject:forKey:] + 59
4 AppKit 0x00007fff85b428c4 -[NSPopUpButtonCell _menuLocationForEvent:inCellFrame:ofView:] + 581
5 AppKit 0x00007fff85b430fd -[NSPopUpButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 132
6 AppKit 0x00007fff857cbbcc -[NSControl mouseDown:] + 820
7 AppKit 0x00007fff857c353e -[NSWindow sendEvent:] + 6853
8 AppKit 0x00007fff857bf674 -[NSApplication sendEvent:] + 5761
9 AppKit 0x00007fff856d524a -[NSApplication run] + 636
10 AppKit 0x00007fff85679c06 NSApplicationMain + 869
11 Demiurge 0x0000000100001772 main + 34
12 libdyld.dylib 0x00007fff83d377e1 start + 0
13 ??? 0x0000000000000003 0x0 + 3
)

Hi,

the error message says, a dictionary is created with a nil value (with the initWithObjects:forKeys:count) method.
Have you ever used the debugger? Set an exception breakpoint and watch the variables. The clang debugger is very helpful even for log messages or printing out variables instead of NSLog statements.

Hi Stefan,

Thanks for your reply. I have been googling for a while, re-reading the docs, using the debugger and even tried Instruments, tracking Core Data faults, leaks and zombies. I finally found the error, but using none of the above.

It came from this instruction:

[_popUp setFont:newFont];

Not really explicitly given by the error message, isn’t it? I’m sending NIL as a font somewhere. but where? :frowning:

Now I’m really re-reading this doc about the Font Manager, the “default font manager”, the “selected font”, the “converted font” and all of this garbage. Oh, please, give me back my old setFont (geneva, 12, []). :lol:

set a (normal) breakpoint at this line with condition newFont == nil and look at the backtrace.

I’d generally avoid to use custom fonts on standard UI elements.

So do I. but here I use the menu title as the enclosing customView’s title. I could have done this a more standard way, but when the user click on the title, I find it better to display the menu content with the same font as the title of the custom view.

Using the Font Manager, the user can set all the subviews titles at once. This is acceptable, because I’m not rewriting Pages :slight_smile: but a small utility application. Using notification, it’s a breeze. if I use the font manager correctly, and obviously I’m not. :confused: