OFFLoader: Use a temporary vector to store vertices instead of a raw array
Prevents crash on certain malformed inputs but they still cause a validation failure.pull/675/head
parent
fba7ede639
commit
7a5bc6eca3
|
@ -192,8 +192,8 @@ void OFFImporter::InternReadFile( const std::string& pFile,
|
||||||
throw DeadlyImportError("OFF: There are no valid faces");
|
throw DeadlyImportError("OFF: There are no valid faces");
|
||||||
|
|
||||||
// allocate storage for the output vertices
|
// allocate storage for the output vertices
|
||||||
aiVector3D* verts = new aiVector3D[mesh->mNumVertices];
|
std::vector<aiVector3D> verts;
|
||||||
mesh->mVertices = verts;
|
verts.reserve(mesh->mNumVertices);
|
||||||
|
|
||||||
// second: now parse all face indices
|
// second: now parse all face indices
|
||||||
buffer = old;
|
buffer = old;
|
||||||
|
@ -219,12 +219,14 @@ void OFFImporter::InternReadFile( const std::string& pFile,
|
||||||
idx = numVertices-1;
|
idx = numVertices-1;
|
||||||
}
|
}
|
||||||
faces->mIndices[m] = p++;
|
faces->mIndices[m] = p++;
|
||||||
*verts++ = tempPositions[idx];
|
verts.push_back(tempPositions[idx]);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
++faces;
|
++faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mesh->mVertices = new aiVector3D[verts.size()];
|
||||||
|
memcpy(mesh->mVertices, &verts[0], verts.size() * sizeof(aiVector3D));
|
||||||
// generate the output node graph
|
// generate the output node graph
|
||||||
pScene->mRootNode = new aiNode();
|
pScene->mRootNode = new aiNode();
|
||||||
pScene->mRootNode->mName.Set("<OFFRoot>");
|
pScene->mRootNode->mName.Set("<OFFRoot>");
|
||||||
|
|
Loading…
Reference in New Issue