Add exception handling when creating new objects on level loading
parent
62fddd6d4f
commit
0d1b97510d
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "graphics/model/model_manager.h"
|
||||
|
||||
#include "common/logger.h"
|
||||
#include "common/resources/inputstream.h"
|
||||
|
||||
#include "graphics/model/model_input.h"
|
||||
|
@ -32,8 +33,12 @@ CModel& CModelManager::GetModel(const std::string& modelName)
|
|||
if (it != m_models.end())
|
||||
return it->second;
|
||||
|
||||
std::string modelFile = "models-new/" + modelName + ".txt";
|
||||
|
||||
GetLogger()->Debug("Loading new model: %s\n", modelFile.c_str());
|
||||
|
||||
CInputStream stream;
|
||||
stream.open("models-new/" + modelName + ".txt");
|
||||
stream.open(modelFile.c_str());
|
||||
if (!stream.is_open())
|
||||
throw CModelIOException(std::string("Could not open file '") + modelName + "'");
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "object/motion/motionhuman.h"
|
||||
#include "object/motion/motiontoto.h"
|
||||
#include "object/object.h"
|
||||
#include "object/object_create_exception.h"
|
||||
#include "object/object_manager.h"
|
||||
#include "object/scene_conditions.h"
|
||||
#include "object/task/task.h"
|
||||
|
@ -3523,16 +3524,25 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
|
||||
float dirAngle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI;
|
||||
bool trainer;
|
||||
CObject* obj = m_objMan->CreateObject(
|
||||
pos, dirAngle,
|
||||
type,
|
||||
line->GetParam("power")->AsFloat(1.0f),
|
||||
line->GetParam("z")->AsFloat(1.0f),
|
||||
line->GetParam("h")->AsFloat(0.0f),
|
||||
trainer = line->GetParam("trainer")->AsBool(false),
|
||||
line->GetParam("toy")->AsBool(false),
|
||||
line->GetParam("option")->AsInt(0)
|
||||
);
|
||||
CObject* obj = nullptr;
|
||||
try
|
||||
{
|
||||
obj = m_objMan->CreateObject(
|
||||
pos, dirAngle,
|
||||
type,
|
||||
line->GetParam("power")->AsFloat(1.0f),
|
||||
line->GetParam("z")->AsFloat(1.0f),
|
||||
line->GetParam("h")->AsFloat(0.0f),
|
||||
trainer = line->GetParam("trainer")->AsBool(false),
|
||||
line->GetParam("toy")->AsBool(false),
|
||||
line->GetParam("option")->AsInt(0)
|
||||
);
|
||||
}
|
||||
catch (const CObjectCreateException& e)
|
||||
{
|
||||
GetLogger()->Error("Error loading level object: %s\n", e.what());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_fixScene && type == OBJECT_HUMAN)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue