[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49573] trunk/blender/source/blender/ collada: COLLADA: #29058 Fixed crash when illegal reference to non existing camera object is found .

Gaia Clary gaia.clary at machinimatrix.org
Sun Aug 5 12:23:35 CEST 2012


Revision: 49573
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49573
Author:   gaiaclary
Date:     2012-08-05 10:23:34 +0000 (Sun, 05 Aug 2012)
Log Message:
-----------
COLLADA: #29058 Fixed crash when illegal reference to non existing camera object is found. And report a warning to the console)

Modified Paths:
--------------
    trunk/blender/source/blender/collada/AnimationImporter.cpp
    trunk/blender/source/blender/collada/DocumentImporter.cpp

Modified: trunk/blender/source/blender/collada/AnimationImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/AnimationImporter.cpp	2012-08-05 09:31:48 UTC (rev 49572)
+++ trunk/blender/source/blender/collada/AnimationImporter.cpp	2012-08-05 10:23:34 UTC (rev 49573)
@@ -804,8 +804,15 @@
 	AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map);
 
 	bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
-	COLLADAFW::Node *root = root_map.find(node->getUniqueId()) == root_map.end() ? node : root_map[node->getUniqueId()];
-	Object *ob = is_joint ? armature_importer->get_armature_for_joint(root) : object_map.find(node->getUniqueId())->second;
+	COLLADAFW::UniqueId uid = node->getUniqueId();
+	COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid];
+
+	Object *ob;
+	if(is_joint)
+		ob = armature_importer->get_armature_for_joint(root);
+	else
+		ob = object_map.find(uid) == object_map.end() ? NULL : object_map.find(uid)->second;
+
 	if (!ob) {
 		fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str());
 		return;
@@ -1179,6 +1186,11 @@
 	const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras();
 	for (unsigned int i = 0; i < nodeCameras.getCount(); i++) {
 		const COLLADAFW::Camera *camera  = (COLLADAFW::Camera *) FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
+		if ( camera == NULL ) {
+			// Can happen if the node refers to an unknown camera.
+			continue;
+		}
+
 		const bool is_perspective_type   = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE;
 
 		int addition;

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp	2012-08-05 09:31:48 UTC (rev 49572)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp	2012-08-05 10:23:34 UTC (rev 49573)
@@ -308,7 +308,7 @@
 {
 	const COLLADAFW::UniqueId& cam_uid = camera->getInstanciatedObjectId();
 	if (uid_camera_map.find(cam_uid) == uid_camera_map.end()) {	
-		fprintf(stderr, "Couldn't find camera by UID.\n");
+		// fprintf(stderr, "Couldn't find camera by UID.\n");
 		return NULL;
 	}
 
@@ -443,7 +443,13 @@
 		}
 		while (camera_done < camera.getCount()) {
 			ob = create_camera_object(camera[camera_done], sce);
-			objects_done->push_back(ob);
+			if (ob == NULL) {
+				std::string id = node->getOriginalId();
+				std::string name = node->getName();
+				fprintf(stderr, "<node id=\"%s\", name=\"%s\" >...contains a reference to an unknown instance_camera.\n", id.c_str(), name.c_str());
+			}
+			else
+				objects_done->push_back(ob);
 			++camera_done;
 		}
 		while (lamp_done < lamp.getCount()) {




More information about the Bf-blender-cvs mailing list