Have better behavior than aborting when a bad kart is found (especially relevant with the add-on manager coming)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6152 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -133,6 +133,15 @@ void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node)
|
||||
{
|
||||
std::string icon_file("");
|
||||
node.get("icon", &icon_file);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (icon_file.size() == 0)
|
||||
{
|
||||
std::cerr << "Cannot load powerup " << type << ", no 'icon' attribute under XML node\n";
|
||||
assert(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
m_all_icons[type] = material_manager->getMaterial(icon_file,
|
||||
/* full_path */ false,
|
||||
/*make_permanent */ true);
|
||||
|
||||
@@ -121,9 +121,12 @@ void KartModel::loadInfo(const XMLNode &node)
|
||||
*/
|
||||
KartModel::~KartModel()
|
||||
{
|
||||
if(m_animated_node)
|
||||
if (m_animated_node)
|
||||
{
|
||||
m_animated_node->setAnimationEndCallback(NULL);
|
||||
m_animated_node->drop();
|
||||
m_animated_node->drop();
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<4; i++)
|
||||
{
|
||||
if(m_wheel_node[i])
|
||||
@@ -222,7 +225,7 @@ void KartModel::attachModel(scene::ISceneNode **node)
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Loads the 3d model and all wheels.
|
||||
*/
|
||||
void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
bool KartModel::loadModels(const KartProperties &kart_properties)
|
||||
{
|
||||
std::string full_path = kart_properties.getKartDir()+"/"+m_model_filename;
|
||||
m_mesh = irr_driver->getAnimatedMesh(full_path);
|
||||
@@ -231,9 +234,9 @@ void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
Vec3 min, max;
|
||||
if(!m_mesh)
|
||||
{
|
||||
printf("Problems loading mesh '%s' - aborting.\n",
|
||||
full_path.c_str());
|
||||
exit(-2);
|
||||
printf("Problems loading mesh '%s' - kart '%s' will not be available\n",
|
||||
full_path.c_str(), kart_properties.getIdent().c_str());
|
||||
return false;
|
||||
}
|
||||
MeshTools::minMax3D(m_mesh, &min, &max);
|
||||
Vec3 size = max-min;
|
||||
@@ -269,6 +272,8 @@ void KartModel::loadModels(const KartProperties &kart_properties)
|
||||
m_wheel_model[i] = irr_driver->getMesh(full_wheel);
|
||||
// FIXME: wheel handling still missing.
|
||||
} // for i<4
|
||||
|
||||
return true;
|
||||
} // loadModels
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
~KartModel();
|
||||
KartModel* makeCopy();
|
||||
void loadInfo(const XMLNode &node);
|
||||
void loadModels(const KartProperties &kart_properties);
|
||||
bool loadModels(const KartProperties &kart_properties);
|
||||
void attachModel(scene::ISceneNode **node);
|
||||
scene::IAnimatedMesh*
|
||||
getModel() const { return m_mesh; }
|
||||
|
||||
@@ -123,6 +123,8 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
std::ostringstream msg;
|
||||
msg << "Couldn't load kart properties '" << filename <<
|
||||
"': no kart node.";
|
||||
|
||||
delete m_kart_model;
|
||||
throw std::runtime_error(msg.str());
|
||||
}
|
||||
getAllData(root);
|
||||
@@ -161,8 +163,18 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
|
||||
// Only load the model if the .kart file has the appropriate version,
|
||||
// otherwise warnings are printed.
|
||||
if(m_version>=1)
|
||||
m_kart_model->loadModels(*this);
|
||||
if (m_version >= 1)
|
||||
{
|
||||
const bool success = m_kart_model->loadModels(*this);
|
||||
if (!success)
|
||||
{
|
||||
delete m_kart_model;
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath();
|
||||
throw std::runtime_error("Cannot load kart models");
|
||||
}
|
||||
}
|
||||
|
||||
if(m_gravity_center_shift.getX()==UNDEFINED)
|
||||
{
|
||||
m_gravity_center_shift.setX(0);
|
||||
|
||||
@@ -146,12 +146,22 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
if(!f) return false;
|
||||
fclose(f);
|
||||
|
||||
KartProperties* kart_properties = new KartProperties(config_filename);
|
||||
|
||||
KartProperties* kart_properties;
|
||||
try
|
||||
{
|
||||
kart_properties = new KartProperties(config_filename);
|
||||
}
|
||||
catch (std::runtime_error& err)
|
||||
{
|
||||
std::cerr << "Giving up loading '" << config_filename.c_str()
|
||||
<< "' : " << err.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the version of the kart file is not supported,
|
||||
// ignore this .kart file
|
||||
if( kart_properties->getVersion()<stk_config->m_min_kart_version ||
|
||||
kart_properties->getVersion()>stk_config->m_max_kart_version)
|
||||
if (kart_properties->getVersion() < stk_config->m_min_kart_version ||
|
||||
kart_properties->getVersion() > stk_config->m_max_kart_version)
|
||||
{
|
||||
fprintf(stderr, "Warning: kart '%s' is not supported by this binary, ignored.\n",
|
||||
kart_properties->getIdent().c_str());
|
||||
|
||||
Reference in New Issue
Block a user