diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_AsyncTextureUpdater.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_AsyncTextureUpdater.cpp index 0402846d4e..4dcfcc0be2 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_AsyncTextureUpdater.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_AsyncTextureUpdater.cpp @@ -506,9 +506,12 @@ void ERS_CLASS_AsyncTextureUpdater::ProcessVRAMUpdate(int Index, ERS_STRUCT_Scen if (PrioritizeQueueByVisualImpact_) { int HighestTargetLevel = Scene->Models[Index]->TargetTextureLevelVRAM; - float Priority = HighestTargetLevel / Scene->Models[Index]->MaxTextureLevel_; - int InsertLocationIndex = PushWorkItems_.size() * Priority; - PushWorkItems_.insert(PushWorkItems_.end() - InsertLocationIndex, Scene->Models[Index]); + + if (HighestTargetLevel != 0) { + float Priority = HighestTargetLevel / Scene->Models[Index]->MaxTextureLevel_; + int InsertLocationIndex = PushWorkItems_.size() * Priority; + PushWorkItems_.insert(PushWorkItems_.end() - InsertLocationIndex, Scene->Models[Index]); + } } else { PushWorkItems_.push_back(Scene->Models[Index]); } @@ -543,9 +546,13 @@ void ERS_CLASS_AsyncTextureUpdater::ProcessRAMUpdate(int Index, ERS_STRUCT_Scene if (PrioritizeQueueByVisualImpact_) { int HighestTargetLevel = Scene->Models[Index]->TargetTextureLevelVRAM; - float Priority = HighestTargetLevel / Scene->Models[Index]->MaxTextureLevel_; - int InsertLocationIndex = LoadWorkItems_.size() * Priority; - LoadWorkItems_.insert(LoadWorkItems_.end() - InsertLocationIndex, Scene->Models[Index]); + + if (HighestTargetLevel != 0) { + float Priority = HighestTargetLevel / Scene->Models[Index]->MaxTextureLevel_; + int InsertLocationIndex = LoadWorkItems_.size() * Priority; + LoadWorkItems_.insert(LoadWorkItems_.end() - InsertLocationIndex, Scene->Models[Index]); + } + } else { LoadWorkItems_.push_back(Scene->Models[Index]); } diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp index a3d2fa84ff..ee0bfac51b 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.cpp @@ -510,31 +510,39 @@ bool ERS_CLASS_ExternalModelLoader::LoadModel(std::string ModelPath, ERS_STRUCT_ std::string ModelFileName = ModelPath.substr(ModelPath.find_last_of("/") + 1, ModelPath.size() - 1); // Load Via Assimp - const aiScene* Scene = Data.ModelImporter.ReadFile(ModelPath, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices); - if (!Scene || Scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !Scene->mRootNode) { - SystemUtils_->Logger_->Log(std::string(std::string("External Model Loading Error: ") + std::string(Data.ModelImporter.GetErrorString())).c_str(), 10); - Data.ModelScene = nullptr; - return false; - } - SystemUtils_->Logger_->Log("Finished Loading External Model, Processing Geometry/Textures", 3); + try { + const aiScene* Scene = Data.ModelImporter.ReadFile(ModelPath, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_PreTransformVertices | aiProcess_JoinIdenticalVertices); - // Process Geometry, Identify Textures - ProcessNode(Data, Data.Model, Scene->mRootNode, Scene, ModelDirectory); - if (!PerformModelSanityChecks(*Data.Model)) { - return false; - } - DetectBoundingBox(Data.Model); - CalculateTotalVertsIndices(Data.Model); + if (!Scene || Scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !Scene->mRootNode) { + SystemUtils_->Logger_->Log(std::string(std::string("External Model Loading Error: ") + std::string(Data.ModelImporter.GetErrorString())).c_str(), 10); + Data.ModelScene = nullptr; + return false; + } + SystemUtils_->Logger_->Log("Finished Loading External Model, Processing Geometry/Textures", 3); + + // Process Geometry, Identify Textures + ProcessNode(Data, Data.Model, Scene->mRootNode, Scene, ModelDirectory); + if (!PerformModelSanityChecks(*Data.Model)) { + return false; + } + DetectBoundingBox(Data.Model); + CalculateTotalVertsIndices(Data.Model); - // Update Struct - Data.ModelOriginDirectoryPath = ModelPath; - Data.ModelScene = (aiScene*)Scene; - Data.ModelFileName = ModelFileName; + // Update Struct + Data.ModelOriginDirectoryPath = ModelPath; + Data.ModelScene = (aiScene*)Scene; + Data.ModelFileName = ModelFileName; - // Load Textures - ProcessModelTextures(Data); + // Load Textures + ProcessModelTextures(Data); + + return true; + + } catch (const DeadlyImportError& e) { + SystemUtils_->Logger_->Log("Assimp Threw DeadlyImportError, Aborting Load", 8); + return false; + } - return true; } diff --git a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h index 6eec395008..44c2352f4c 100644 --- a/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h +++ b/Source/Core/Utils/ERS_CLASS_ExternalModelLoader/ERS_CLASS_ExternalModelLoader.h @@ -33,6 +33,7 @@ #include #include #include +#include // Internal Libraries (BG convention: use <> instead of "") #include