[Bf-blender-cvs] [d62e6f12257] master: RNA nodetree: improve ImageUser path helper.

Bastien Montagne noreply at git.blender.org
Wed Jun 8 18:00:52 CEST 2022


Commit: d62e6f122575a0a8292e731fecebe663589e81ea
Author: Bastien Montagne
Date:   Wed Jun 8 17:47:45 2022 +0200
Branches: master
https://developer.blender.org/rBd62e6f122575a0a8292e731fecebe663589e81ea

RNA nodetree: improve ImageUser path helper.

Refactor the code, and optimize it slightly (no need e.g. to check for
nodes when the nodetree is of a type that cannot have image user nodes).

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

M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 53f207328c9..65a8d8bf24a 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1610,26 +1610,31 @@ static char *rna_Node_path(const PointerRNA *ptr)
 char *rna_Node_ImageUser_path(const PointerRNA *ptr)
 {
   bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
-  bNode *node;
-  char name_esc[sizeof(node->name) * 2];
+  if (!ELEM(ntree->type, NTREE_SHADER, NTREE_CUSTOM)) {
+    return NULL;
+  }
 
-  for (node = ntree->nodes.first; node; node = node->next) {
-    if (node->type == SH_NODE_TEX_ENVIRONMENT) {
-      NodeTexEnvironment *data = node->storage;
-      if (&data->iuser != ptr->data) {
-        continue;
+  for (bNode *node = ntree->nodes.first; node; node = node->next) {
+    switch (node->type) {
+      case SH_NODE_TEX_ENVIRONMENT: {
+        NodeTexEnvironment *data = node->storage;
+        if (&data->iuser != ptr->data) {
+          continue;
+        }
+        break;
       }
-    }
-    else if (node->type == SH_NODE_TEX_IMAGE) {
-      NodeTexImage *data = node->storage;
-      if (&data->iuser != ptr->data) {
-        continue;
+      case SH_NODE_TEX_IMAGE: {
+        NodeTexImage *data = node->storage;
+        if (&data->iuser != ptr->data) {
+          continue;
+        }
+        break;
       }
-    }
-    else {
-      continue;
+      default:
+        continue;
     }
 
+    char name_esc[sizeof(node->name) * 2];
     BLI_str_escape(name_esc, node->name, sizeof(name_esc));
     return BLI_sprintfN("nodes[\"%s\"].image_user", name_esc);
   }



More information about the Bf-blender-cvs mailing list