Rewrote Window::setNextFocusable() to address a bug in the management of the search iterator. Covertiy reported bug "Undefined behavior may result; the program may crash or subtly misbehave.

In osgWidget::​Window::​setNextFocusable(): An invalid or past-the-end iterator is being used."
This commit is contained in:
Robert Osfield 2016-06-09 12:08:47 +01:00
parent d3f5aef5ef
commit 02eb8de191

View File

@ -758,25 +758,28 @@ bool Window::setFirstFocusable() {
return false;
}
bool Window::setNextFocusable() {
bool Window::setNextFocusable()
{
WidgetList focusList;
if(!getFocusList(focusList)) return false;
WidgetList::iterator w = focusList.begin();
// TODO: This needs to be a more complicated object, since the focus may be
// in a child Window instead of a Widget.
unsigned int focusedIndex = 0;
for(unsigned int i = 0; w != focusList.end(); w++, i++) if(*w == _focused) {
focusedIndex = i;
break;
WidgetList::iterator witr;
for(witr = focusList.begin();
witr != focusList.end();
++witr)
{
if (*witr==_focused)
{
// found current focused widget, move to next widget the one we want to focus on
++witr;
break;
}
}
if(focusedIndex < focusList.size() - 1) _setFocused((++w)->get());
if (witr!=focusList.end()) _setFocused(witr->get());
else _setFocused(focusList.front().get());
return true;