Fixed various crashes related to having more players than karts

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8805 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-06-02 22:34:28 +00:00
parent ba1cf47ac3
commit a5d4275554
3 changed files with 13 additions and 5 deletions

View File

@ -526,7 +526,8 @@ const std::string& DynamicRibbonWidget::getSelectionIDString(const int playerID)
return nothing;
}
// -----------------------------------------------------------------------------
const irr::core::stringw& DynamicRibbonWidget::getSelectionText(const int playerID)
irr::core::stringw DynamicRibbonWidget::getSelectionText(const int playerID)
{
RibbonWidget* row = (RibbonWidget*)(m_rows.size() == 1 ? m_rows.get(0) : getSelectedRibbon(playerID));
@ -535,6 +536,7 @@ const irr::core::stringw& DynamicRibbonWidget::getSelectionText(const int player
static const irr::core::stringw nothing = "";
return nothing;
}
// -----------------------------------------------------------------------------
RibbonWidget* DynamicRibbonWidget::getRowContaining(Widget* w)
{
@ -1009,7 +1011,7 @@ bool DynamicRibbonWidget::findItemInRows(const char* name, int* p_row, int* p_id
int row = -1;
int id;
for (int r=0; r<m_row_amount; r++)
for (int r=0; r<m_rows.size(); r++)
{
id = m_rows[r].findItemNamed(name);
if (id > -1)
@ -1032,9 +1034,10 @@ bool DynamicRibbonWidget::setSelection(int item_id, const int playerID, const bo
//printf("****DynamicRibbonWidget::setSelection()****\n");
if ((unsigned int)item_id >= m_items.size()) return false;
m_selected_item[playerID] = item_id;
const std::string& name = m_items[item_id].m_code_name;
int row;

View File

@ -239,7 +239,7 @@ namespace GUIEngine
const std::string& getSelectionIDString(const int playerID);
/** Get the user-visible text of the selected item */
const irr::core::stringw& getSelectionText(const int playerID);
irr::core::stringw getSelectionText(const int playerID);
/** Returns a read-only list of items added to this ribbon */
const std::vector<ItemDescription>& getItems() const { return m_items; }

View File

@ -115,7 +115,12 @@ namespace GUIEngine
const std::string& getSelectionIDString(const int playerID);
/** Returns the user-visible text of the selection */
const irr::core::stringw& getSelectionText(const int playerID) { return m_children[m_selection[playerID]].m_text; }
irr::core::stringw getSelectionText(const int playerID)
{
const int selection = m_selection[playerID];
if (selection < 0 || selection >= m_children.size()) return "";
return m_children[selection].m_text;
}
/** Sets the ID of the selected item within the ribbon */
void setSelection(const int i, const int playerID) { m_selection[playerID] = i; updateSelection(); }