From 1c23d2e8de13738d06ee84de5861a0cbc4300ff4 Mon Sep 17 00:00:00 2001 From: bzt Date: Wed, 30 Oct 2019 01:11:34 +0100 Subject: [PATCH] More reduced scope fix by wasting more memory... --- code/M3D/M3DExporter.cpp | 10 +++++----- code/M3D/M3DImporter.cpp | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/code/M3D/M3DExporter.cpp b/code/M3D/M3DExporter.cpp index 9e774fa7f..9ba48b125 100644 --- a/code/M3D/M3DExporter.cpp +++ b/code/M3D/M3DExporter.cpp @@ -264,7 +264,7 @@ uint32_t M3DExporter::mkColor(aiColor4D* c) // add a material to the output M3D_INDEX M3DExporter::addMaterial(const aiMaterial *mat) { - unsigned int i, mi = -1U; + unsigned int mi = -1U; aiColor4D c; aiString name; ai_real f; @@ -274,13 +274,14 @@ M3D_INDEX M3DExporter::addMaterial(const aiMaterial *mat) strcmp((char*)&name.data, AI_DEFAULT_MATERIAL_NAME)) { // check if we have saved a material by this name. This has to be done // because only the referenced materials should be added to the output - for(i = 0; i < m3d->nummaterial; i++) + for(unsigned int i = 0; i < m3d->nummaterial; i++) if(!strcmp((char*)&name.data, m3d->material[i].name)) { mi = i; break; } // if not found, add the material to the output if(mi == -1U) { + unsigned int k; mi = m3d->nummaterial++; m3d->material = (m3dm_t*)M3D_REALLOC(m3d->material, m3d->nummaterial * sizeof(m3dm_t)); @@ -291,9 +292,7 @@ M3D_INDEX M3DExporter::addMaterial(const aiMaterial *mat) m3d->material[mi].numprop = 0; m3d->material[mi].prop = NULL; // iterate through the material property table and see what we got - for(unsigned int k = 0; - k < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); - k++) { + for(k = 0; k < 15; k++) { unsigned int j; if(m3d_propertytypes[k].format == m3dpf_map) continue; @@ -341,6 +340,7 @@ M3D_INDEX M3DExporter::addMaterial(const aiMaterial *mat) mat->GetTexture((aiTextureType)aiTxProps[k].type, aiTxProps[k].index, &name, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { + unsigned int i; for(j = name.length-1; j > 0 && name.data[j]!='.'; j++); if(j && name.data[j]=='.' && (name.data[j+1]=='p' || name.data[j+1]=='P') && diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index d732387ce..873c51f97 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -629,7 +629,6 @@ void M3DImporter::calculateOffsetMatrix(aiNode *pNode, aiMatrix4x4 *m) void M3DImporter::populateMesh(aiMesh *pMesh, std::vector *faces, std::vector *vertices, std::vector *normals, std::vector *texcoords, std::vector *colors, std::vector *vertexids) { - unsigned int i, j; ai_assert(pMesh != nullptr); ai_assert(faces != nullptr); @@ -644,6 +643,7 @@ void M3DImporter::populateMesh(aiMesh *pMesh, std::vector *faces, std::v " numnormals ", normals->size(), " numtexcoord ", texcoords->size(), " numbones ", m3d->numbone); if(vertices->size() && faces->size()) { + unsigned int i; pMesh->mNumFaces = faces->size(); pMesh->mFaces = new aiFace[pMesh->mNumFaces]; std::copy(faces->begin(), faces->end(), pMesh->mFaces); @@ -682,11 +682,12 @@ void M3DImporter::populateMesh(aiMesh *pMesh, std::vector *faces, std::v pMesh->mBones[i]->mOffsetMatrix = aiMatrix4x4(); } if(vertexids->size()) { + unsigned int j; // first count how many vertices we have per bone for(i = 0; i < vertexids->size(); i++) { - unsigned int s = m3d->vertex[vertexids->at(i)].skinid, k; + unsigned int s = m3d->vertex[vertexids->at(i)].skinid; if(s != -1U && s!= -2U) { - for(k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { + for(unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name)); for(j = 0; j < pMesh->mNumBones; j++) { if(pMesh->mBones[j]->mName == name) { @@ -707,9 +708,9 @@ void M3DImporter::populateMesh(aiMesh *pMesh, std::vector *faces, std::v } // fill up with data for(i = 0; i < vertexids->size(); i++) { - unsigned int s = m3d->vertex[vertexids->at(i)].skinid, k; + unsigned int s = m3d->vertex[vertexids->at(i)].skinid; if(s != -1U && s!= -2U) { - for(k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { + for(unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name)); for(j = 0; j < pMesh->mNumBones; j++) { if(pMesh->mBones[j]->mName == name) {