diff --git a/src/Nazara/3D/Loaders/OBJ/Loader.cpp b/src/Nazara/3D/Loaders/OBJ/Loader.cpp index 1754bf40e..0d295c795 100644 --- a/src/Nazara/3D/Loaders/OBJ/Loader.cpp +++ b/src/Nazara/3D/Loaders/OBJ/Loader.cpp @@ -184,13 +184,13 @@ namespace NzString mtlLib = parser.GetMtlLib(); if (parameters.loadMaterials && !mtlLib.IsEmpty()) { - NzString baseDir = stream.GetDirectory(); - NzFile file(baseDir + mtlLib); + NzFile file(stream.GetDirectory() + mtlLib); if (file.Open(NzFile::ReadOnly | NzFile::Text)) { NzMTLParser materialParser(file); if (materialParser.Parse()) { + NzString baseDir = file.GetDirectory(); for (unsigned int i = 0; i < meshCount; ++i) { const NzString& matName = materials[meshes[i].material]; diff --git a/src/Nazara/3D/Loaders/OBJ/OBJParser.cpp b/src/Nazara/3D/Loaders/OBJ/OBJParser.cpp index 90a3f55df..b0f5b749c 100644 --- a/src/Nazara/3D/Loaders/OBJ/OBJParser.cpp +++ b/src/Nazara/3D/Loaders/OBJ/OBJParser.cpp @@ -170,23 +170,65 @@ bool NzOBJParser::Parse() break; } - pos += offset; + if (p < 0) + { + p += m_positions.size() + 1; + if (p < 0) + { + Error("Vertex index out of range (" + NzString::Number(p) + " < 0"); + error = true; + break; + } + } + else + p--; + + if (n < 0) + { + n += m_normals.size() + 1; + if (n < 0) + { + Error("Vertex index out of range (" + NzString::Number(n) + " < 0"); + error = true; + break; + } + } + else + n--; + + if (t < 0) + { + t += m_texCoords.size() + 1; + if (t < 0) + { + Error("Vertex index out of range (" + NzString::Number(t) + " < 0"); + error = true; + break; + } + } + else + t--; if (static_cast(p) >= m_positions.size()) { - Error("Vertex index out of range " + NzString::Number(p) + " > " + NzString::Number(m_positions.size())); + Error("Vertex index out of range (" + NzString::Number(p) + " >= " + NzString::Number(m_positions.size()) + ')'); + error = true; break; } else if (n >= 0 && static_cast(n) >= m_normals.size()) { - Error("Normal index out of range " + NzString::Number(n) + " > " + NzString::Number(m_normals.size())); + Error("Normal index out of range (" + NzString::Number(n) + " >= " + NzString::Number(m_normals.size()) + ')'); + error = true; break; } else if (t >= 0 && static_cast(t) >= m_texCoords.size()) { - Error("TexCoord index out of range " + NzString::Number(t) + " > " + NzString::Number(m_texCoords.size())); + Error("TexCoord index out of range (" + NzString::Number(t) + " >= " + NzString::Number(m_texCoords.size()) + ')'); + error = true; break; } + + pos += offset; } if (!error) @@ -234,7 +276,7 @@ bool NzOBJParser::Parse() if (m_currentLine[1] == ' ') { NzString param = m_currentLine.Substr(2); - if (param != '0' && param != '1' && param != "on" && param != "off") + if (param != "all" && param != "on" && param != "off" && !param.IsNumber()) UnrecognizedLine(); } else @@ -339,6 +381,12 @@ bool NzOBJParser::Parse() } } + if (m_meshes.empty()) + { + NazaraError("No meshes"); + return false; + } + m_materials.resize(matCount); for (auto it : materials) m_materials[it.second] = it.first;