[Bf-blender-cvs] [51fa44522f7] geometry-nodes: Geometry Nodes: Add errors for out of sync sockets and properties

Hans Goudey noreply at git.blender.org
Fri Oct 30 17:42:17 CET 2020


Commit: 51fa44522f7412f7db55628d4044e3939a4328fa
Author: Hans Goudey
Date:   Fri Oct 30 11:42:11 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB51fa44522f7412f7db55628d4044e3939a4328fa

Geometry Nodes: Add errors for out of sync sockets and properties

Theoretically the modifier's properties could be changed or removed by
Python, so it may be useful to have errors printed and added to the
modifier in that case.

I kept the check as a separate step from the `compute_geometry`
pass because the object is needed to set the modifier error message.
But it could easily be moved there in the future.

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

M	source/blender/modifiers/intern/MOD_nodes.cc

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

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index a36cdee5e11..dc7882b1586 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -683,13 +683,52 @@ static GeometryPtr compute_geometry(const DerivedNodeTree &tree,
   return output_geometry;
 }
 
-static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx), Mesh *mesh)
+/**
+ * \note This could be done in #initialize_group_input, though that would require adding the
+ * the object as a paramete, so it's likely better to this check as a separate step.
+ */
+static void check_property_socket_sync(const Object *ob, ModifierData *md)
+{
+  NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
+
+  int i = 0;
+  LISTBASE_FOREACH_INDEX (const bNodeSocket *, socket, &nmd->node_group->inputs, i) {
+    /* The first socket is the special geometry socket for the modifier object. */
+    if (i == 0 && socket->type == SOCK_GEOMETRY) {
+      continue;
+    }
+
+    IDProperty *property = IDP_GetPropertyFromGroup(nmd->settings.properties, socket->identifier);
+    if (property == nullptr) {
+      BKE_modifier_set_error(ob,
+                             md,
+                             "Missing property for input socket \"%s\" (\"%s\") ",
+                             socket->name,
+                             socket->identifier);
+      continue;
+    }
+
+    const SocketPropertyType *property_type = get_socket_property_type(*socket);
+    if (!property_type->is_correct_type(*property)) {
+      BKE_modifier_set_error(ob,
+                             md,
+                             "Property type does not match for input socket \"%s\" (\"%s\") ",
+                             socket->name,
+                             socket->identifier);
+      continue;
+    }
+  }
+}
+
+static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
 {
   NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
   if (nmd->node_group == nullptr) {
     return mesh;
   }
 
+  check_property_socket_sync(ctx->object, md);
+
   NodeTreeRefMap tree_refs;
   DerivedNodeTree tree{nmd->node_group, tree_refs};
   ResourceCollector resources;
@@ -745,9 +784,9 @@ static void draw_property_for_socket(uiLayout *layout,
 
   /* The property should be created in #MOD_nodes_update_interface with the correct type. */
   IDProperty *property = IDP_GetPropertyFromGroup(modifier_props, socket.identifier);
-  BLI_assert(property != nullptr);
-  BLI_assert(property_type->is_correct_type(*property));
 
+  /* IDProperties can be removed with python, so there could be a situation where
+   * there isn't a property for a socket or it doesn't have the correct type. */
   if (property != nullptr && property_type->is_correct_type(*property)) {
     char rna_path[128];
     BLI_snprintf(rna_path, ARRAY_SIZE(rna_path), "[\"%s\"]", socket.identifier);



More information about the Bf-blender-cvs mailing list