fix Collada: wrong usage of pointer and hidden redeclaration
authorGaia Clary <gaia.clary@machinimatrix.org>
Sun, 11 Mar 2018 19:32:47 +0000 (20:32 +0100)
committerGaia Clary <gaia.clary@machinimatrix.org>
Sun, 11 Mar 2018 19:59:50 +0000 (20:59 +0100)
* Suspicious usage of pointer:

  short *type = 0; // this creates a null pointer

When this is later used for anything then blender would crash.
After following the code and check what happens i strongly believe
the author wanted to use a short and not a pointer to a short here.

* local variable where reused later in same function
While this did no harm, i still felt it was better to use a different
name here to make things more separated:

- moved variable declaraiotns into loop (for int a=0; ...)
- renamed uv_images to uv_image_set
- renamed index variable from i to j in inner loop that
  reused same index name from outer loop

source/blender/collada/DocumentImporter.cpp
source/blender/collada/GeometryExporter.cpp
source/blender/collada/ImageExporter.cpp
source/blender/collada/MeshImporter.cpp

index 4837eb0..08ac6e6 100644 (file)
@@ -474,9 +474,9 @@ void DocumentImporter::create_constraints(ExtraTags *et, Object *ob)
 {
        if (et && et->isProfile("blender")) {
                std::string name;
-               short* type = 0;
-               et->setData("type", type);
-               BKE_constraint_add_for_object(ob, "Test_con", *type);
+               short type = 0;
+               et->setData("type", &type);
+               BKE_constraint_add_for_object(ob, "Test_con", type);
                
        }
 }
@@ -587,8 +587,8 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
                        ++lamp_done;
                }
                while (controller_done < controller.getCount()) {
-                       COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry *)controller[controller_done];
-                       ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map);
+                       COLLADAFW::InstanceGeometry *geometry = (COLLADAFW::InstanceGeometry *)controller[controller_done];
+                       ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map, material_texture_mapping_map);
                        if (ob == NULL) {
                                report_unknown_reference(*node, "instance_controller");
                        }
index 73b00fd..bc02750 100644 (file)
@@ -149,8 +149,8 @@ void GeometryExporter::operator()(Object *ob)
                }
                else {
                        bool all_uv_layers = !this->export_settings->active_uv_only;
-                       std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
-                       createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind);
+                       std::set<Image *> uv_image_set = bc_getUVImages(ob, all_uv_layers);
+                       createPolylists(uv_image_set, has_uvs, has_color, ob, me, geom_id, norind);
                }
        }
        
index 93be7de..9954755 100644 (file)
@@ -203,8 +203,8 @@ bool ImagesExporter::hasImages(Scene *sce)
        
        for (node = this->export_settings->export_set; node; node = node->next) {
                Object *ob = (Object *)node->link;
-               int a;
-               for (a = 0; a < ob->totcol; a++) {
+
+               for (int a = 0; a < ob->totcol; a++) {
                        Material *ma = give_current_material(ob, a + 1);
 
                        // no material, but check all of the slots
index 6ca53c6..2e26512 100644 (file)
@@ -552,7 +552,7 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len)
 {
        CustomData edata;
        MEdge *medge;
-       int i, totedge;
+       int totedge;
 
        if (len == 0)
                return;
@@ -572,7 +572,7 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len)
 
        /* set default flags */
        medge = &mesh->medge[mesh->totedge];
-       for (i = 0; i < len; i++, medge++)
+       for (int i = 0; i < len; i++, medge++)
                medge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT;
 
        mesh->totedge = totedge;
@@ -606,12 +606,12 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me)
                                unsigned int edge_count  = mp->getFaceCount();
                                unsigned int *indices    = mp->getPositionIndices().getData();
                                
-                               for (int i = 0; i < edge_count; i++, med++) {
+                               for (int j = 0; j < edge_count; j++, med++) {
                                        med->bweight = 0;
                                        med->crease  = 0;
                                        med->flag   |= ME_LOOSEEDGE;
-                                       med->v1      = indices[2 * i];
-                                       med->v2      = indices[2 * i + 1];
+                                       med->v1      = indices[2 * j];
+                                       med->v2      = indices[2 * j + 1];
                                }
                        }
                }