From a04abf296799c019e27bedbb0ddc3fed299522aa Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 30 Jul 2005 20:12:41 +0000 Subject: [PATCH] Fail more quietly while loading This was SVN commit r2565. --- source/graphics/MapReader.cpp | 22 ++++++++++++++-------- source/graphics/ObjectEntry.cpp | 12 ++++++++++-- source/maths/Matrix3D.h | 10 +++++----- source/ps/FileUnpacker.cpp | 6 ++++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 221e370a2c..2b16905d0a 100755 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -104,7 +104,7 @@ void CMapReader::UnpackObjects() for (u32 i=0; iGetPatch(i,j)->m_MiniPatches[m][k]; - + mp.Tex1 = m_TerrainTextures[tileptr->m_Tex1Index]; mp.Tex1Priority = tileptr->m_Priority; @@ -332,7 +332,7 @@ void CXMLReader::ReadEnvironment(XMBElement parent) XERO_ITER_EL(parent, element) { int element_name = element.getNodeName(); - + XMBAttributeList attrs = element.getAttributes(); if (element_name == el_suncolour) { @@ -420,12 +420,18 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time) debug_warn("Invalid XML data - DTD shouldn't allow this"); } - HEntity ent = g_EntityManager.create(g_EntityTemplateCollection.getTemplate(TemplateName), Position, Orientation); - - if (! ent) - LOG(ERROR, LOG_CATEGORY, "Failed to create entity '%ls'", TemplateName.c_str()); + CBaseEntity* base = g_EntityTemplateCollection.getTemplate(TemplateName); + if (! base) + LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", TemplateName.c_str()); else - ent->SetPlayer(g_Game->GetPlayer(PlayerID)); + { + HEntity ent = g_EntityManager.create(base, Position, Orientation); + + if (! ent) + LOG(ERROR, LOG_CATEGORY, "Failed to create entity of type '%ls'", TemplateName.c_str()); + else + ent->SetPlayer(g_Game->GetPlayer(PlayerID)); + } completed_jobs++; LDR_CHECK_TIMEOUT(completed_jobs, total_jobs); diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index 892a928260..0388fab43c 100755 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -67,7 +67,14 @@ bool CObjectEntry::BuildRandomVariant(const CObjectBase::variation_key& vars, CO if (var_id < 0 || var_id >= grp->size()) { LOG(ERROR, LOG_CATEGORY, "Internal error (BuildRandomVariant: %d not in 0..%d)", var_id, grp->size()-1); - continue; + // Carry on as best we can, by using some arbitrary variant (rather + // than choosing none, else we might end up with no model or texture) + if (grp->size()) + var_id = 0; + else + // ... unless there aren't any variants in this group, in which + // case just give up and try the next group + continue; } CObjectBase::Variant& var ((*grp)[var_id]); @@ -92,7 +99,7 @@ bool CObjectEntry::BuildRandomVariant(const CObjectBase::variation_key& vars, CO // So, erase all existing animations which are overridden by this variant: for (std::vector::iterator it = var.m_Anims.begin(); it != var.m_Anims.end(); ++it) chosenAnims.erase(chosenAnims.lower_bound(it->m_AnimName), chosenAnims.upper_bound(it->m_AnimName)); - // and this insert the new ones: + // and then insert the new ones: for (std::vector::iterator it = var.m_Anims.begin(); it != var.m_Anims.end(); ++it) chosenAnims.insert(make_pair(it->m_AnimName, *it)); } @@ -117,6 +124,7 @@ bool CObjectEntry::BuildRandomVariant(const CObjectBase::variation_key& vars, CO for (std::map::iterator it = chosenProps.begin(); it != chosenProps.end(); ++it) props.push_back(it->second); + // TODO: This is all wrong, since it breaks the order (which vars_it relies on) // Build the model: diff --git a/source/maths/Matrix3D.h b/source/maths/Matrix3D.h index b76a7db45c..28734abde2 100755 --- a/source/maths/Matrix3D.h +++ b/source/maths/Matrix3D.h @@ -68,13 +68,13 @@ public: // set this matrix to a rotation described by given quaternion void SetRotation(const CQuaternion& quat); - // concatentate a rotation about the X axis onto this matrix + // concatenate a rotation about the X axis onto this matrix void RotateX(float angle); - // concatentate a rotation about the Y axis onto this matrix + // concatenate a rotation about the Y axis onto this matrix void RotateY(float angle); - // concatentate a rotation about the Z axis onto this matrix + // concatenate a rotation about the Z axis onto this matrix void RotateZ(float angle); - // concatentate a rotation described by given quaternion + // concatenate a rotation described by given quaternion void Rotate(const CQuaternion& quat); // set this matrix to given translation @@ -88,7 +88,7 @@ public: // set this matrix to the given scaling matrix void SetScaling(float x_scale, float y_scale, float z_scale); - // concatentate given scaling matrix onto this matrix + // concatenate given scaling matrix onto this matrix void Scale(float x_scale, float y_scale, float z_scale); // calculate the inverse of this matrix, store in dst diff --git a/source/ps/FileUnpacker.cpp b/source/ps/FileUnpacker.cpp index 9588139b7a..a6ead26d80 100755 --- a/source/ps/FileUnpacker.cpp +++ b/source/ps/FileUnpacker.cpp @@ -43,10 +43,12 @@ void CFileUnpacker::Read(const char* filename,const char magicstr[4]) // avoid vfs_load complaining about missing data files (which happens // too often). better to check here than squelch internal VFS error // reporting. we disable this in release mode to avoid a speed hit. -#ifndef NDEBUG + // UPDATE: We don't disable this in release mode, because vfs_load now + // complains about missing files when running in release +//#ifndef NDEBUG if(!vfs_exists(filename)) throw CFileOpenError(); -#endif +//#endif // load the whole thing into memory Handle hm = vfs_load(filename, m_Buf, m_Size);