ComboBox bug

Archives Forums/MaxGUI Bug Reports/ComboBox bug

ima747(Posted 2010) [#1]
You can't add 2 items with the same name to a combobox. Possibly a mac only bug, haven't tested elsewhere.


Import MaxGui.Drivers
Local window:TGadget = CreateWindow("Settings", 0, 0, 430, 250, Null, WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS | WINDOW_CENTER)
Local selector:TGadget = CreateComboBox(0, 0, 200, 24, window)
Local onLine:Int = 0 ' just to see where it dies
For Local onMode:Int = 0 Until 30
	Print "line " + onLine
	AddGadgetItem(selector, "An Item")
	Print " - added OK!"

Output I get is
line 1
 - added OK!
line 2
2010-07-21 12:22:11.779 guitest:bmx[241:607] *** Assertion failure in -[NSMenu itemAtIndex:], /SourceCache/AppKit/AppKit-1038.32/Menus.subproj/NSMenu.m:779
2010-07-21 12:22:11.788 guitest:bmx[241:607] Invalid parameter not satisfying: (index >= 0) && (index < [_itemArray count])

if you change "An Item" to "An Item" + onLine there is no problem.

SebHoll(Posted 2010) [#2]
Confirmed here on 10.6.

Although you could very easily argue that what point is there in a choice if they all have the same label to the user? I suppose icons could be different, but I don't think Apple would say that was good interface design.

ima747(Posted 2010) [#3]
I encountered it because I was creating a list of screen resolutions with refresh rate, all at 32bpp. However for whatever reason it reported 640x480 32bpp @60hz twice... don't know why... and as a result my list would crash. It's something I filter out now to prevent double entries (like you said UI wise you shouldn't have double entries), but still took a while to figure out what was going on since the code used to work fine and just stopped with no change on my part. Especially worrying since i used the same snippet in 2 programs...

I'm sure an example could be created where you might want identicle names, perhaps as you said the icon, or the order, would make them make sense to an end user. For rough example and the sake of argument:

Green Objects: Always
Some Times
Red Objects: Always

Not a REAL example, but just a thought...

skidracer(Posted 2010) [#4]
IMHO, it can/ought to be fixed, docs here

suggest a more optimal approach hopefully without this problem can be done talking directly with receiver, hmph

skidracer(Posted 2010) [#5]
Fixed in next release.

SebHoll(Posted 2010) [#6]
Fixed using NSPopupButton implementation in SourceForge repo (rev. 19).

Conforms better to Apple's HIG and of course NSPopupButton supports item icons whereas NSComboBox doesn't so it's better to use it when appropriate.