Revision: 35416
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35416
Author:   jesterking
Date:     2011-03-09 01:13:28 +0000 (Wed, 09 Mar 2011)
Log Message:
-----------
Fix [#26037] Import Collada crashes Blender
Submitted by David Roy

Multiple nodes can reference the same geometry, and specify the same materials. 
This lead
to the import code overwriting material mappings of faces in a destructive way. 
Instead of
just writing the material bindings always we now keep book of what 
geometry+material mapping
we've already handled.

Modified Paths:
--------------
    trunk/blender/source/blender/collada/MeshImporter.cpp
    trunk/blender/source/blender/collada/MeshImporter.h

Modified: trunk/blender/source/blender/collada/MeshImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/MeshImporter.cpp       2011-03-09 
00:23:26 UTC (rev 35415)
+++ trunk/blender/source/blender/collada/MeshImporter.cpp       2011-03-09 
01:13:28 UTC (rev 35416)
@@ -803,6 +803,18 @@
                return NULL;
        }
        
+       // different nodes can point to same geometry, but still also specify 
the same materials
+       // again. Make sure we don't overwrite them on the next occurrences, so 
keep list of
+       // what we already have handled.
+       std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId>::iterator it;
+       it=materials_mapped_to_geom.find(*geom_uid);
+       while(it!=materials_mapped_to_geom.end()) {
+               if(it->second == ma_uid) return NULL; // do nothing if already 
found
+               it++;
+       }
+       // first time we get geom_uid, ma_uid pair. Save for later check.
+       materials_mapped_to_geom.insert(std::pair<COLLADAFW::UniqueId, 
COLLADAFW::UniqueId>(*geom_uid, ma_uid));
+       
        Material *ma = uid_material_map[ma_uid];
        assign_material(ob, ma, ob->totcol + 1);
        

Modified: trunk/blender/source/blender/collada/MeshImporter.h
===================================================================
--- trunk/blender/source/blender/collada/MeshImporter.h 2011-03-09 00:23:26 UTC 
(rev 35415)
+++ trunk/blender/source/blender/collada/MeshImporter.h 2011-03-09 01:13:28 UTC 
(rev 35416)
@@ -91,6 +91,7 @@
        };
        typedef std::map<COLLADAFW::MaterialId, std::vector<Primitive> > 
MaterialIdPrimitiveArrayMap;
        std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> 
geom_uid_mat_mapping_map; // crazy name!
+       std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> 
materials_mapped_to_geom; //< materials that have already been mapped to a 
geometry. A pair of geom uid and mat uid, one geometry can have several 
materials
        
 
        void set_face_indices(MFace *mface, unsigned int *indices, bool quad);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to