Bladeren bron

More reduced scope fix by wasting more memory...

bzt 6 jaren geleden
bovenliggende
commit
1c23d2e8de
2 gewijzigde bestanden met toevoegingen van 11 en 10 verwijderingen
  1. 5 5
      code/M3D/M3DExporter.cpp
  2. 6 5
      code/M3D/M3DImporter.cpp

+ 5 - 5
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') &&

+ 6 - 5
code/M3D/M3DImporter.cpp

@@ -629,7 +629,6 @@ void M3DImporter::calculateOffsetMatrix(aiNode *pNode, aiMatrix4x4 *m)
 void M3DImporter::populateMesh(aiMesh *pMesh, std::vector<aiFace> *faces, std::vector<aiVector3D> *vertices,
     std::vector<aiVector3D> *normals, std::vector<aiVector3D> *texcoords, std::vector<aiColor4D> *colors,
     std::vector<unsigned int> *vertexids) {
-    unsigned int i, j;
 
     ai_assert(pMesh != nullptr);
     ai_assert(faces != nullptr);
@@ -644,6 +643,7 @@ void M3DImporter::populateMesh(aiMesh *pMesh, std::vector<aiFace> *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<aiFace> *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<aiFace> *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) {