Commit 46c24d2c authored by cutealien's avatar cutealien

Add checks for invalid indices in .obj file loading and return 0 instead of...

Add checks for invalid indices in .obj file loading and return 0 instead of crashing when that happens. 
This applies (slightly modified) patch #296 from patchtracker. Thx @mbohnen for report and patch.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4983 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 7b46d868
...@@ -225,18 +225,25 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -225,18 +225,25 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
// sends the buffer sizes and gets the actual indices // sends the buffer sizes and gets the actual indices
// if index not set returns -1 // if index not set returns -1
s32 Idx[3]; s32 Idx[3];
Idx[1] = Idx[2] = -1; Idx[0] = Idx[1] = Idx[2] = -1;
// read in next vertex's data // read in next vertex's data
u32 wlength = copyWord(vertexWord, linePtr, WORD_BUFFER_LENGTH, endPtr); u32 wlength = copyWord(vertexWord, linePtr, WORD_BUFFER_LENGTH, endPtr);
// this function will also convert obj's 1-based index to c++'s 0-based index // this function will also convert obj's 1-based index to c++'s 0-based index
retrieveVertexIndices(vertexWord, Idx, vertexWord+wlength+1, vertexBuffer.size(), textureCoordBuffer.size(), normalsBuffer.size()); retrieveVertexIndices(vertexWord, Idx, vertexWord+wlength+1, vertexBuffer.size(), textureCoordBuffer.size(), normalsBuffer.size());
v.Pos = vertexBuffer[Idx[0]]; if ( -1 != Idx[0] && Idx[0] < (irr::s32)vertexBuffer.size() )
if ( -1 != Idx[1] ) v.Pos = vertexBuffer[Idx[0]];
else
{
os::Printer::log("Invalid vertex index in this line:", wordBuffer.c_str(), ELL_ERROR);
delete [] buf;
return 0;
}
if ( -1 != Idx[1] && Idx[1] < (irr::s32)textureCoordBuffer.size() )
v.TCoords = textureCoordBuffer[Idx[1]]; v.TCoords = textureCoordBuffer[Idx[1]];
else else
v.TCoords.set(0.0f,0.0f); v.TCoords.set(0.0f,0.0f);
if ( -1 != Idx[2] ) if ( -1 != Idx[2] && Idx[2] < (irr::s32)normalsBuffer.size() )
v.Normal = normalsBuffer[Idx[2]]; v.Normal = normalsBuffer[Idx[2]];
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment