#10733 closed bug (fixed)
[BOptionPopUp] can crash when containing a SeparatorItem
Reported by: | ttcoder | Owned by: | jscipione |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Kits/Interface Kit | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
BOptionPopUp does not provide explicit separator-item support, but it exposes MenuField()->Menu()->AddSeparatorItem()
to do so. I used that to make a menu look better/more structured, but realized that all further calls to GetOptionAt() will crash, probably because unlike BMenuItem, SeparatorItem lacks a Message()
field.
Attachments (3)
Change History (12)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
I bet we don't want to skip options without message. So, no, the check should happen on the "if (outValue != NULL)" line.
comment:3 by , 11 years ago
That would fix the crash in my case just as well indeed.
One might want to update the BeBook (if necessary) in that case, to mention that GetOptionAt() would return true
not only for menu items that were created as actual "options" (with the AddOptionAt() method) but also for custom-made menu items and for separator items. Thus it would rarely if ever return 'false'. Probably makes sense. I'm happy either way.. With one caveat:
Beware that SelectOptionFor()..
http://cgit.haiku-os.org/haiku/tree/src/kits/interface/OptionControl.cpp#n95
... does not initialize its "int32 optionValue" parameter (that's an awful practice that plagues the whole Haiku source tree, but that's a discussion for another time and place..) when passing it to GetOptionAt(), so one would need to either 1) initialize that variable, knowing it won't be affected in GetOptionAt(), or 2) change GetOptionAt() so that it sets it to 0 (or -1) if it cannot find the Message() field in the menu item, otherwise we get the dreaded "undefined behavior"..!
by , 11 years ago
Attachment: | 0001_1-BOptionPopUp-check-for-non-NULL-Message.patch added |
---|
Version 1 (most inclusive, tries hard to return all items as options)
comment:5 by , 11 years ago
patch: | 0 → 1 |
---|
by , 11 years ago
Attachment: | 0001_1-BOptionPopUp-check-for-non-NULL-Message.2.patch added |
---|
Version 1 (most inclusive, tries hard to return all items as options)
by , 11 years ago
Attachment: | 0001_2-BOptionPopUp-check-for-non-NULL-Message.patch added |
---|
Version 2 (consistent with SetValue(), which checks for Message() at the same early stage too).
comment:6 by , 11 years ago
Heck why not :-) It's in an area I am skilled enough for, and you guys need encouragement/contribs to keep up the good work. Attached two versions, the latter being my personal favorite, but both of them fix the crash. Let's see if I messed up following the directions in the wiki or not..
comment:7 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in hrev47375 thanks to ttcoder for reporting and supplying a patch, Axel and korli for reviewing and waddlesplash for bringing the bug to my attention.
I guess this diff would be best, as this returns false when the field is not present (by opposed to testing for the field only later down in the inner if() ):
Here's the stack crawl BTW: