diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index c16cfc0f0..72141e437 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -100,7 +100,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass //Read the Mesh File: boost::scoped_ptr mIOWrapper( new CIrrXML_IOStreamReader( file.get())); - XmlReader* MeshFile = irr::io::createIrrXMLReader(mIOWrapper.get()); + boost::scoped_ptr MeshFile(irr::io::createIrrXMLReader(mIOWrapper.get())); if(!MeshFile)//parse the xml file throw DeadlyImportError("Failed to create XML Reader for "+pFile); @@ -108,21 +108,21 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass DefaultLogger::get()->debug("Mesh File opened"); //Read root Node: - if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="mesh")) + if(!(XmlRead(MeshFile.get()) && string(MeshFile->getNodeName())=="mesh")) { throw DeadlyImportError("Root Node is not ! "+pFile+" "+MeshFile->getNodeName()); } //eventually load shared geometry - XmlRead(MeshFile);//shared geometry is optional, so we need a reed for the next two if's + XmlRead(MeshFile.get());//shared geometry is optional, so we need a reed for the next two if's if(MeshFile->getNodeName()==string("sharedgeometry")) { - unsigned int NumVertices=GetAttribute(MeshFile, "vertexcount");; + unsigned int NumVertices=GetAttribute(MeshFile.get(), "vertexcount");; - XmlRead(MeshFile); + XmlRead(MeshFile.get()); while(MeshFile->getNodeName()==string("vertexbuffer")) { - ReadVertexBuffer(m_SharedGeometry, MeshFile, NumVertices); + ReadVertexBuffer(m_SharedGeometry, MeshFile.get(), NumVertices); } } @@ -136,13 +136,13 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass //-------------------Read the submeshs and materials:----------------------- std::list > SubMeshes; vector Materials; - XmlRead(MeshFile); + XmlRead(MeshFile.get()); while(MeshFile->getNodeName()==string("submesh")) { SubMesh* theSubMesh=new SubMesh(); - theSubMesh->MaterialName=GetAttribute(MeshFile, "material"); + theSubMesh->MaterialName=GetAttribute(MeshFile.get(), "material"); DefaultLogger::get()->debug("Loading Submehs with Material: "+theSubMesh->MaterialName); - ReadSubMesh(*theSubMesh, MeshFile); + ReadSubMesh(*theSubMesh, MeshFile.get()); //just a index in a array, we add a mesh in each loop cycle, so we get indicies like 0, 1, 2 ... n; //so it is important to do this before pushing the mesh in the vector! @@ -170,9 +170,9 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass vector Animations; if(MeshFile->getNodeName()==string("skeletonlink")) { - string SkeletonFile=GetAttribute(MeshFile, "name"); + string SkeletonFile=GetAttribute(MeshFile.get(), "name"); LoadSkeleton(SkeletonFile, Bones, Animations); - XmlRead(MeshFile); + XmlRead(MeshFile.get()); } else { @@ -185,7 +185,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass //now there might be boneassignments for the shared geometry: if(MeshFile->getNodeName()==string("boneassignments")) { - ReadBoneWeights(m_SharedGeometry, MeshFile); + ReadBoneWeights(m_SharedGeometry, MeshFile.get()); } diff --git a/code/OgreMaterial.cpp b/code/OgreMaterial.cpp index 95ca1cf42..48ab75523 100644 --- a/code/OgreMaterial.cpp +++ b/code/OgreMaterial.cpp @@ -148,12 +148,22 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const } } } + //Fill the stream boost::scoped_ptr MaterialFile(MatFilePtr); - vector FileData(MaterialFile->FileSize()); - MaterialFile->Read(&FileData[0], MaterialFile->FileSize(), 1); - BaseImporter::ConvertToUTF8(FileData); + if(MaterialFile->FileSize()>0) + { + vector FileData(MaterialFile->FileSize()); + MaterialFile->Read(&FileData[0], MaterialFile->FileSize(), 1); + BaseImporter::ConvertToUTF8(FileData); - ss << &FileData[0]; + FileData.push_back('\0');//terminate the string with zero, so that the ss can parse it correctly + ss << &FileData[0]; + } + else + { + DefaultLogger::get()->warn("Material " + MaterialName + " seams to be empty"); + return NULL; + } } //create the material