ResourceManager::Load never returns null, throws exceptions instead.

This commit is contained in:
William Moberg
2016-01-15 15:25:01 +01:00
parent 76f90ab031
commit f5ea4d513c
5 changed files with 117 additions and 97 deletions
+1 -5
View File
@@ -2,12 +2,8 @@
Model::Model(std::string fileName)
{
//Load the RawModel asyncronously, this will be done on a separate thread in the background.
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
//If it is null, the model is not done yet, so tell resourceManager to try constructing me again later.
if (m_RawModel == nullptr) {
throw StillLoadingException();
}
for (auto& group : m_RawModel->MaterialGroups) {
if (!group.TexturePath.empty()) {
+12 -4
View File
@@ -84,13 +84,21 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
continue;
}
Model* model = ResourceManager::Load<::Model, true>(resource);
if (model == nullptr) {
model = ResourceManager::Load<::Model>("Models/Core/Error.obj");
Model* model;
try {
model = ResourceManager::Load<::Model, true>(resource);
} catch (const Resource::StillLoadingException&) {
//continue;
model = ResourceManager::Load<::Model>("Models/Core/UnitRaptor.obj");
} catch (const std::exception&) {
try {
model = ResourceManager::Load<::Model>("Models/Core/Error.obj");
} catch (const std::exception&) {
continue;
}
}
glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, world);
for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, world));
jobs.push_back(modelJob);