Fixed crash if more than one kart is connected to the server (since the

network kart screen will only show local karts now).
This commit is contained in:
hiker 2015-12-10 17:37:28 +11:00
parent e0b3de17f6
commit 770d05f0de
4 changed files with 12 additions and 7 deletions

View File

@ -817,7 +817,8 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id,
} }
} }
void KartSelectionScreen::updateKartWidgetModel(uint8_t widget_id, // ----------------------------------------------------------------------------
void KartSelectionScreen::updateKartWidgetModel(int widget_id,
const std::string& selection, const std::string& selection,
const irr::core::stringw& selectionText) const irr::core::stringw& selectionText)
{ {

View File

@ -107,8 +107,9 @@ protected:
void updateKartStats(uint8_t widget_id, void updateKartStats(uint8_t widget_id,
const std::string& selection); const std::string& selection);
/** updates model of a kart widget, to have the good selection when the user validates */ /** updates model of a kart widget, to have the good selection when the
void updateKartWidgetModel(uint8_t widget_id, * user validates */
void updateKartWidgetModel(int widget_id,
const std::string& selection, const std::string& selection,
const irr::core::stringw& selectionText); const irr::core::stringw& selectionText);

View File

@ -144,7 +144,7 @@ void NetworkKartSelectionScreen::playerConfirm(const int playerID)
void NetworkKartSelectionScreen::playerSelected(uint8_t player_id, void NetworkKartSelectionScreen::playerSelected(uint8_t player_id,
const std::string &kart_name) const std::string &kart_name)
{ {
uint8_t widget_id = -1; int widget_id = -1;
for (unsigned int i = 0; i < m_id_mapping.size(); i++) for (unsigned int i = 0; i < m_id_mapping.size(); i++)
{ {
Log::info("NKSS", "Checking race id %d : mapped of %d is %d", Log::info("NKSS", "Checking race id %d : mapped of %d is %d",
@ -153,7 +153,10 @@ void NetworkKartSelectionScreen::playerSelected(uint8_t player_id,
widget_id = i; widget_id = i;
} }
assert(widget_id>=0 && widget_id < m_kart_widgets.size()); // This selection was for a remote kart, which is not shown
// Just ignore it.
if(widget_id==-1)
return;
KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name, KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name,
irr::core::stringw(kart_name.c_str())); irr::core::stringw(kart_name.c_str()));

View File

@ -33,11 +33,11 @@ protected:
virtual ~NetworkKartSelectionScreen(); virtual ~NetworkKartSelectionScreen();
virtual void playerConfirm(const int playerID); virtual void playerConfirm(const int playerID);
void considerKartHovered(uint8_t widget_id, std::string selection);
public: public:
virtual void init() OVERRIDE; virtual void init() OVERRIDE;
virtual bool onEscapePressed() OVERRIDE; virtual bool onEscapePressed() OVERRIDE;
virtual void playerSelected(uint8_t race_id, const std::string &kart_name); virtual void playerSelected(uint8_t player_id,
const std::string &kart_name);
}; };
#endif // NETWORK_KART_SELECTION_HPP #endif // NETWORK_KART_SELECTION_HPP