From b8ed6fbcef3e945f105ed275ce529c142d83c6cc Mon Sep 17 00:00:00 2001 From: acgessler Date: Fri, 3 May 2013 23:16:56 +0200 Subject: [PATCH] Fix Heap corruption in BlenderImporter::ConvertMesh function. closes #36 --- code/BlenderLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 3b9200b14..4bad638e2 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -644,14 +644,18 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co // collect per-submesh numbers std::map per_mat; + std::map per_mat_verts; for (int i = 0; i < mesh->totface; ++i) { const MFace& mf = mesh->mface[i]; per_mat[ mf.mat_nr ]++; + per_mat_verts[ mf.mat_nr ] += mf.v4?4:3; } + for (int i = 0; i < mesh->totpoly; ++i) { const MPoly& mp = mesh->mpoly[i]; per_mat[ mp.mat_nr ]++; + per_mat_verts[ mp.mat_nr ] += mp.totloop; } // ... and allocate the corresponding meshes @@ -665,8 +669,8 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co temp->push_back(new aiMesh()); aiMesh* out = temp->back(); - out->mVertices = new aiVector3D[it.second*4]; - out->mNormals = new aiVector3D[it.second*4]; + out->mVertices = new aiVector3D[per_mat_verts[it.first]]; + out->mNormals = new aiVector3D[per_mat_verts[it.first]]; //out->mNumFaces = 0 //out->mNumVertices = 0