Fix T41513 Avoid adding NULL values into object lists when lamp- and controller-instances could not be created.

This commit is contained in:
2014-08-25 19:03:02 +02:00
parent 8d0b3e9902
commit 0fc240dadb
2 changed files with 31 additions and 13 deletions

View File

@@ -483,6 +483,17 @@ void DocumentImporter::create_constraints(ExtraTags *et, Object *ob)
}
}
void DocumentImporter::report_unknown_reference(const COLLADAFW::Node &node, const std::string object_type)
{
std::string id = node.getOriginalId();
std::string name = node.getName();
fprintf(stderr,
"<node id=\"%s\", name=\"%s\" >...contains a reference to an unknown %s.\n",
id.c_str(),
name.c_str(),
object_type.c_str());
}
std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
{
Object *ob = NULL;
@@ -538,10 +549,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
material_texture_mapping_map);
if (ob == NULL) {
fprintf(stderr,
"<node id=\"%s\", name=\"%s\" >...contains a reference to an unknown instance_mesh.\n",
id.c_str(),
name.c_str());
report_unknown_reference(*node, "instance_mesh");
}
else {
objects_done->push_back(ob);
@@ -554,9 +562,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
while (camera_done < camera.getCount()) {
ob = create_camera_object(camera[camera_done], sce);
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());
report_unknown_reference(*node, "instance_camera");
}
else {
objects_done->push_back(ob);
@@ -568,18 +574,28 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
}
while (lamp_done < lamp.getCount()) {
ob = create_lamp_object(lamp[lamp_done], sce);
objects_done->push_back(ob);
if (parent_node == NULL) {
root_objects->push_back(ob);
if (ob == NULL) {
report_unknown_reference(*node, "instance_lamp");
}
else {
objects_done->push_back(ob);
if (parent_node == NULL) {
root_objects->push_back(ob);
}
}
++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);
objects_done->push_back(ob);
if (parent_node == NULL) {
root_objects->push_back(ob);
if (ob == NULL) {
report_unknown_reference(*node, "instance_controller");
}
else {
objects_done->push_back(ob);
if (parent_node == NULL) {
root_objects->push_back(ob);
}
}
++controller_done;
}

View File

@@ -171,6 +171,8 @@ private:
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map;
std::string import_from_version;
void report_unknown_reference(const COLLADAFW::Node &node, const std::string object_type);
};
#endif