Fix crash in case of invalid kart types (e.g. 'default', which the
exporter actually writes if 'default' is selected).
This commit is contained in:
parent
e8b8bbdd3b
commit
50acbea315
@ -178,9 +178,17 @@ public:
|
||||
const KartProperties &
|
||||
getDefaultKartProperties() const {return *m_default_kart_properties; }
|
||||
|
||||
const KartProperties &
|
||||
getKartProperties(std::string type) { return *m_kart_properties[type]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the kart properties for a certain type of kart.
|
||||
* \throw out_of_range if there is no data for 'type'.
|
||||
* \param type Type of kart (e.g. heavy, medium, ...).
|
||||
*/
|
||||
const KartProperties& getKartProperties(std::string type)
|
||||
{
|
||||
return *m_kart_properties.at(type);
|
||||
} // getKartProperties
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
const PlayerDifficulty * getPlayerDifficulty(PerPlayerDifficulty difficulty)
|
||||
{ return m_player_difficulties[difficulty]; }
|
||||
}
|
||||
|
@ -178,8 +178,19 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
|
||||
const XMLNode* root = new XMLNode(filename);
|
||||
std::string kart_type;
|
||||
|
||||
if (root->get("type", &kart_type))
|
||||
copyFrom(&stk_config->getKartProperties(kart_type));
|
||||
{
|
||||
// Handle the case that kart_type might be incorrect
|
||||
try
|
||||
{
|
||||
copyFrom(&stk_config->getKartProperties(kart_type));
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
copyFrom(&stk_config->getDefaultKartProperties());
|
||||
} // try .. catch
|
||||
}
|
||||
else
|
||||
copyFrom(&stk_config->getDefaultKartProperties());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user