From 65fc86e49c634c66791e479a2f8cf0aa887d9278 Mon Sep 17 00:00:00 2001 From: hybrid Date: Wed, 29 Aug 2007 16:09:32 +0000 Subject: [PATCH] Avoid crash if vertex data failed to load. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@870 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CColladaFileLoader.cpp | 70 +++++++++++++++++++++++--- source/Irrlicht/CColladaFileLoader.h | 2 +- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/source/Irrlicht/CColladaFileLoader.cpp b/source/Irrlicht/CColladaFileLoader.cpp index c13b9471..d4972542 100644 --- a/source/Irrlicht/CColladaFileLoader.cpp +++ b/source/Irrlicht/CColladaFileLoader.cpp @@ -338,6 +338,10 @@ void CColladaFileLoader::readColladaSection(io::IXMLReaderUTF8* reader) //! reads a section and its content void CColladaFileLoader::readLibrarySection(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading library"); + #endif + while(reader->read()) if (reader->getNodeType() == io::EXN_ELEMENT) { @@ -496,8 +500,8 @@ void CColladaFileLoader::readNodeSection(io::IXMLReaderUTF8* reader, scene::ISce // TODO: set transformation correctly into node. // currently this isn't done correctly. Need to get transformation, // rotation and scale from the matrix. - core::vector3df trans = transform.getTranslation(); - core::vector3df rot = transform.getRotationDegrees(); + const core::vector3df& trans = transform.getTranslation(); + const core::vector3df& rot = transform.getRotationDegrees(); node->setPosition(trans); node->setRotation(rot); @@ -533,6 +537,10 @@ core::matrix4 CColladaFileLoader::readLookAtNode(io::IXMLReaderUTF8* reader) //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readSkewNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading skew node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -550,6 +558,10 @@ core::matrix4 CColladaFileLoader::readSkewNode(io::IXMLReaderUTF8* reader) //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readMatrixNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading matrix node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -562,6 +574,10 @@ core::matrix4 CColladaFileLoader::readMatrixNode(io::IXMLReaderUTF8* reader) //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readPerspectiveNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading perspective node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -579,6 +595,10 @@ core::matrix4 CColladaFileLoader::readPerspectiveNode(io::IXMLReaderUTF8* reader //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readRotateNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading rotate node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -587,14 +607,16 @@ core::matrix4 CColladaFileLoader::readRotateNode(io::IXMLReaderUTF8* reader) readFloatsInsideElement(reader, floats, 4); core::quaternion q(floats[0], floats[1], floats[2], floats[3]); - mat = q.getMatrix(); - - return mat; + return q.getMatrix(); } //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readScaleNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading scale node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -611,6 +633,10 @@ core::matrix4 CColladaFileLoader::readScaleNode(io::IXMLReaderUTF8* reader) //! reads a element and its content and creates a matrix from it core::matrix4 CColladaFileLoader::readTranslateNode(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading translate node"); + #endif + core::matrix4 mat; if (reader->isEmptyElement()) return mat; @@ -649,6 +675,10 @@ void CColladaFileLoader::readInstanceNode(io::IXMLReaderUTF8* reader, scene::ISc //! reads a element and stores it as prefab void CColladaFileLoader::readCameraPrefab(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading camera prefab"); + #endif + CCameraPrefab* prefab = new CCameraPrefab(reader->getAttributeValue("id")); if (!reader->isEmptyElement()) @@ -677,6 +707,10 @@ void CColladaFileLoader::readCameraPrefab(io::IXMLReaderUTF8* reader) //! reads a element and stores it in the image section void CColladaFileLoader::readImage(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading image"); + #endif + SColladaImage image; image.Id = reader->getAttributeValue("id"); image.Filename = reader->getAttributeValue("source"); @@ -689,6 +723,10 @@ void CColladaFileLoader::readImage(io::IXMLReaderUTF8* reader) //! reads a element and stores it in the texture section void CColladaFileLoader::readTexture(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading texture"); + #endif + SColladaTexture texture; texture.Id = reader->getAttributeValue("id"); @@ -717,6 +755,10 @@ void CColladaFileLoader::readTexture(io::IXMLReaderUTF8* reader) //! reads a element and stores it in the material section void CColladaFileLoader::readMaterial(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading material"); + #endif + SColladaMaterial material; material.Id = reader->getAttributeValue("id"); @@ -764,6 +806,10 @@ void CColladaFileLoader::readMaterial(io::IXMLReaderUTF8* reader) //! reads a element and stores it as mesh if possible void CColladaFileLoader::readGeometry(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading geometry"); + #endif + core::stringc id = reader->getAttributeValue("id"); core::stringc VertexPositionSource; // each mesh has exactly one member, containing @@ -947,9 +993,13 @@ struct SPolygon //! reads a polygons section and creates a mesh from it void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader, - core::stringc vertexPositionSource, core::array& sources, + const core::stringc& vertexPositionSource, core::array& sources, scene::SMesh* mesh) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading polygon section"); + #endif + core::stringc materialName = reader->getAttributeValue("material"); uriToId(materialName); video::SMaterial mat; @@ -1117,6 +1167,8 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader, // for all input semantics for (u32 k=0; k element and stores it as prefab void CColladaFileLoader::readLightPrefab(io::IXMLReaderUTF8* reader) { + #ifdef COLLADA_READER_DEBUG + os::Printer::log("COLLADA reading light prefab"); + #endif + CLightPrefab* prefab = new CLightPrefab(reader->getAttributeValue("id")); if (!reader->isEmptyElement()) @@ -1335,7 +1391,7 @@ void CColladaFileLoader::readColladaInputs(io::IXMLReaderUTF8* reader, const cor //! parses all collada parameters inside an element and stores them in Parameters void CColladaFileLoader::readColladaParameters(io::IXMLReaderUTF8* reader, - const core::stringc& parentName) + const core::stringc& parentName) { Parameters.clear(); diff --git a/source/Irrlicht/CColladaFileLoader.h b/source/Irrlicht/CColladaFileLoader.h index fe8251e0..fa46ee12 100644 --- a/source/Irrlicht/CColladaFileLoader.h +++ b/source/Irrlicht/CColladaFileLoader.h @@ -265,7 +265,7 @@ private: //! reads a polygons section and creates a mesh from it void readPolygonSection(io::IXMLReaderUTF8* reader, - core::stringc vertexPositionSource, core::array& sources, + const core::stringc& vertexPositionSource, core::array& sources, scene::SMesh* mesh); video::IVideoDriver* Driver;