[Bf-blender-cvs] [769f7650e81] temp-node-error-messages: Add more error messages

Hans Goudey noreply at git.blender.org
Tue Jan 19 22:56:15 CET 2021


Commit: 769f7650e8128e473aeb4ec10d36aed91cddef70
Author: Hans Goudey
Date:   Tue Jan 19 15:56:06 2021 -0600
Branches: temp-node-error-messages
https://developer.blender.org/rB769f7650e8128e473aeb4ec10d36aed91cddef70

Add more error messages

===================================================================

M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
M	source/blender/nodes/intern/node_geometry_exec.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 21ab7f61447..0481018616f 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -773,7 +773,10 @@ ReadAttributePtr GeometryComponent::attribute_get_for_read(const StringRef attri
   if (attribute) {
     return attribute;
   }
-  return this->attribute_get_constant_for_read(domain, data_type, default_value);
+  if (default_value != nullptr) {
+    return this->attribute_get_constant_for_read(domain, data_type, default_value);
+  }
+  return nullptr;
 }
 
 blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_read(
@@ -930,6 +933,7 @@ void OutputAttributePtr::save()
 OutputAttributePtr::~OutputAttributePtr()
 {
   if (attribute_) {
+    /* TODO: Fix that this is printing all the time now, even after applying and saving. */
     CLOG_ERROR(&LOG, "Forgot to call #save or #apply_span_and_save.");
   }
 }
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 46d5cf57618..6a78e1f5072 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -181,17 +181,20 @@ class GeoNodeExecParams {
    * Add an error message displayed at the bottom of the node when displaying the node tree,
    * and potentially elsewhere in Blender.
    */
-  void add_error_message(StringRef message);
+  void error_message_add(const std::string message) const;
 
   /**
    * Creates a read-only attribute based on node inputs. The method automatically detects which
-   * input with the given name is available.
+   * input socket with the given name is available.
+   *
+   * \note Can return null if no attribute with the provided name exists,
+   * in which case an error message is added for the UI.
    */
   ReadAttributePtr get_input_attribute(const StringRef name,
                                        const GeometryComponent &component,
                                        const AttributeDomain domain,
                                        const CustomDataType type,
-                                       const void *default_value) const;
+                                       const void *default_value = nullptr) const;
 
   template<typename T>
   bke::TypedReadAttribute<T> get_input_attribute(const StringRef name,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index 58d67145e75..c0723197b1e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -148,6 +148,9 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
       "A", component, result_domain, result_type, nullptr);
   ReadAttributePtr attribute_b = params.get_input_attribute(
       "B", component, result_domain, result_type, nullptr);
+  if (!attribute_a || !attribute_b) {
+    return;
+  }
 
   do_mix_operation(result_type,
                    node_storage->blend_type,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index eaf13b94eb9..7fdcfd616d5 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -413,6 +413,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
       static_cast<GeometryNodePointDistributeMethod>(params.node().custom1);
 
   if (!geometry_set.has_mesh()) {
+    params.error_message_add("Geometry must contain a mesh");
     params.set_output("Geometry", std::move(geometry_set_out));
     return;
   }
@@ -428,7 +429,8 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
   const MeshComponent &mesh_component = *geometry_set.get_component_for_read<MeshComponent>();
   const Mesh *mesh_in = mesh_component.get_for_read();
 
-  if (mesh_in == nullptr || mesh_in->mpoly == nullptr) {
+  if (mesh_in->mpoly == nullptr) {
+    params.error_message_add("Mesh has no faces");
     params.set_output("Geometry", std::move(geometry_set_out));
     return;
   }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
index d9e69adb860..1337abe0718 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
@@ -86,6 +86,12 @@ static void get_instanced_data__collection(
     return;
   }
 
+  if (BLI_listbase_is_empty(&collection->children) &&
+      BLI_listbase_is_empty(&collection->gobject)) {
+    params.error_message_add("Collection is empty");
+    return;
+  }
+
   const bool use_whole_collection = node.custom2 == 0;
   if (use_whole_collection) {
     InstancedData instance;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
index 0624e04f151..72176b11fdb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc
@@ -62,8 +62,6 @@ static void geo_node_point_translate_exec(GeoNodeExecParams params)
     execute_on_component(params, geometry_set.get_component_for_write<PointCloudComponent>());
   }
 
-  params.add_error_message("TEST HELLO???");
-
   params.set_output("Geometry", std::move(geometry_set));
 }
 
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 025008e3546..fad73e3f10f 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -21,7 +21,7 @@
 
 namespace blender::nodes {
 
-void GeoNodeExecParams::add_error_message(StringRef message)
+void GeoNodeExecParams::error_message_add(const std::string message) const
 {
   bNodeTree *original_ntree = (bNodeTree *)DEG_get_original_id(&(ID &)ntree_);
   if (original_ntree != nullptr) {
@@ -57,7 +57,16 @@ ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
 
   if (found_socket->type == SOCK_STRING) {
     const std::string name = this->get_input<std::string>(found_socket->identifier);
-    return component.attribute_get_for_read(name, domain, type, default_value);
+    if (name.empty()) {
+      return nullptr;
+    }
+
+    ReadAttributePtr attribute = component.attribute_get_for_read(
+        name, domain, type, default_value);
+    if (!attribute) {
+      this->error_message_add(std::string("No attribute with name '") + name + "'.");
+    }
+    return attribute;
   }
   if (found_socket->type == SOCK_FLOAT) {
     const float value = this->get_input<float>(found_socket->identifier);



More information about the Bf-blender-cvs mailing list